1

I'm trying to establish RMI Client Server connectivity where Client and Server are behind different NAT/Firewall using TCP Hole punching mechanism. Currently, I could get the connectivity between client and Server using their Public Ip and port "80". After TCP connection is established I could retrieve the Stub info of RMIServer. Also, I could netstat and see the connection established.

But When trying read the remote object I'm getting following exception

java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is: 
java.net.SocketTimeoutException: Read timed out
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:293)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:190)

On monitoring the connectivity with netstat, I could see the TCP connection gets terminated immediately and its not stable. It would be helpful If I could get any hints on how to maintain or get a stable TCP connection.

Thanks.

user207421
  • 305,947
  • 44
  • 307
  • 483
skmr
  • 19
  • 1
  • 1
  • 3

1 Answers1

-1

The timeout error indicates you were able to open a socket between the client and the server, but that the socket was not serviced in a timely manner, so it closed and gave you that exception.

The last time this happened to me, it happened because the client could not find the correct class libraries in its path. The server attempted to open a socket, the client went off looking for the class library and didn't find it, the socket eventually timed out.

Double check the class path of both your client and server.

bpendell
  • 1
  • 2
  • You have client and server back to front here. Clients open connections: servers accept them. The client got the read timeout, so it was the server that wasn't responding. – user207421 May 16 '14 at 22:54
  • I've seen it happen the other esy where the server tried to send to the client and got a socket error. The server listens on a socket for client requests, then typically spawns a dedicated thread to handle the client on a dedicated socket, while the well known port is freed up to accept more client reqs. Regardless, the first step is to check the classpath. – bpendell May 18 '14 at 03:54
  • Is it fine to use port "80" to establish TCP connection? My client machine gets "connection Timeout" immediately after establishing connection with server. Is there any way to keep TCP connection alive? I tried using socket.setKeepAlive(true), but that doesn't seem to help. – skmr May 20 '14 at 13:02
  • Cross checked the classpath. Everything is fine. But still facing the issue. – skmr May 20 '14 at 13:18
  • Did some looking -- this appears to have shown up on stackoverflow before. http://stackoverflow.com/questions/14332154/error-with-jrmp-connection-establishment The answer there seems to be a network-related issue. What happens if you try to ping that ip address and port? – bpendell May 21 '14 at 13:56
  • Here is another possible answer: http://stackoverflow.com/questions/10422603/what-could-cause-rmi-method-calls-to-fail-intermittently – bpendell May 21 '14 at 13:58
  • when I do a telnet on ip and port, the connection is getting established. Also, Is there a way to connect using random port instead of "80"? – skmr May 28 '14 at 10:05
  • Yes, as per stackoverflow.com/questions/10422603/, I have hashcode() and equals() method on SocketFactory class already . But the problem arises only when I'm trying to connect between private network. It's working fine within LAN. – skmr May 30 '14 at 05:18
  • 1
    It was the server that didn't respond here. Read the question. The client doesn't respond in RMI. You never saw this error in RMI due to the client being busy. Your answer doesn't make sense. If it was a CLASSPATH problem it would be a different error, unless the OP is using a specific response timeout, which he doesn't mention. – user207421 Nov 06 '17 at 05:26