3

I am trying to connect to a remote host via the java program:

socket = new java.net.Socket(host,port);     

I am getting the following exception:

java.net.ConnectException: Connection refused: connect

Tracing IP packets between my computer and the remote host, I see that my computer sent SYN packets three times, and received [RST,ACK] packets three times .

Why does my computer send three SYN packets despite only one connection establishent?

Is it due to the TCP/IP stack of the OS?

Or is it due to Java's implementation of java.net.Socket class?

Pacerier
  • 86,231
  • 106
  • 366
  • 634
Art Spasky
  • 1,635
  • 2
  • 17
  • 30
  • The firewall and java security manager has already been checked on both ends of the connection? This should work. I use this all the time without issue. Try the ol' reboot? – jefflunt Nov 01 '11 at 18:06
  • 1
    The question was not why remote host reset connection but why 3 SYN packets were sent. – Art Spasky Nov 01 '11 at 18:09
  • Could that be a retry? http://stackoverflow.com/questions/1045964/how-to-view-change-socket-connection-timeout-on-linux – James Jithin Nov 01 '11 at 19:12
  • I think that it is retry, but I want to understand does it concern tcp/ip stack implementation or java implementation of Socket class? – Art Spasky Nov 01 '11 at 19:28
  • @ArtSpasky it is the TCP stack, not Java. – user207421 Nov 02 '11 at 00:07

1 Answers1

2

The retransmission of the SYN is probably done to comply with RFC793 :

The TCP must recover from data that is damaged, lost, duplicated, or delivered out of order by the internet communication system. This is achieved by assigning a sequence number to each octet transmitted, and requiring a positive acknowledgment (ACK) from the receiving TCP. If the ACK is not received within a timeout interval, the data is retransmitted.

It makes sense that the SYN would be retried since it's possible that for whatever reason the ACK just got lost. The number of times that that's retransmitted and the timeout would depend on the TCP implementation not Java.

jkysam
  • 5,533
  • 1
  • 21
  • 16
  • 3 SYN pakets were sent within the short interval (less than a second).Three packets from the remote host were received with ACK and RST flags. So I think the reason is not the packet loss or timeout. – Art Spasky Nov 02 '11 at 05:45
  • did 3 SYN packets get sent in a row, or did your computer wait for a ACK/RST packet before sending another SYN? – Dan O Jul 16 '12 at 20:13