2

I want to write a small groovy script.

This is my script, which is working:

s = new Socket("localhost", 1234);
s << "RUN"
s.close()

But I don't want to use the hostname (here it is 'localhost'), I want to use the IP-Adress, but if I write the following Code it doesn't work.

s = new Socket("xx.x.xx.xxx", 1234);
    s << "RUN"
    s.close()

I also tried it this way:

s = new Socket(new Inet4Address("xx.x.xx.xxx"), 1234);
s << "RUN"
s.close()

I get always a connection refused exception:

Caught: java.net.ConnectException: Connection refused: connect at web3.run(web3.groovy:1)

I know, this piece of code does not really make sense, but it is all I need.

Thanks for your help.

Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222
LStrike
  • 1,598
  • 4
  • 26
  • 58

2 Answers2

0

Have you tried this notation?

s = new Socket(InetAddress.getByName("xx.x.xx.xxx"), 1234);
Christoph Metzendorf
  • 7,968
  • 2
  • 31
  • 28
  • No, I haven't. But it doesn't work either. I think this is not a groovy problem, it maybe is a problem with my firewall or anything else on my computer, I haven't figured out yet. If I use 'localhost' everything is fine, if I use '127.0.0.1' it works too, but if I use my real IP address not. – LStrike Jan 20 '11 at 15:50
  • 1
    make sure whatever server your connecting to is binding on the real IP. a lot of servers can be configured to listen only on bound addresses. to test this, simply try a basic telnet onto the host and port – Steven Jan 22 '11 at 00:44
0

Caught: java.net.ConnectException: Connection refused: connect at web3.run(web3.groovy:1)

Looks to specify that the host you are connecting to (web3.groovy:1) is down or not listening on that port?

if its a *nix system. Try:

netstat -na | grep 1234

See if you are actually listening on that system on that port.

ril3y
  • 912
  • 4
  • 10
  • 19