我想编写一个小的groovy脚本。
这是我的脚本,正在运行:
s = new Socket("localhost", 1234);
s << "RUN"
s.close()
但是我不想使用主机名(这里是“localhost”),我想使用IP地址,但是如果我编写以下代码,它将无法正常工作。
s = new Socket("xx.x.xx.xxx", 1234);
s << "RUN"
s.close()
我也这样尝试过:
s = new Socket(new Inet4Address("xx.x.xx.xxx"), 1234);
s << "RUN"
s.close()
我总是遇到连接被拒绝的异常:
Caught: java.net.ConnectException: Connection refused: connect at web3.run(web3.groovy:1)
我知道,这段代码并没有什么意义,但这只是我所需要的。
谢谢你的帮助。
最佳答案
您是否尝试过这种符号?
s = new Socket(InetAddress.getByName("xx.x.xx.xxx"), 1234);
关于sockets - Groovy套接字编程和IP地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4748212/