Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCP connection establishment

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?

like image 688
Art Spasky Avatar asked Dec 07 '25 05:12

Art Spasky


1 Answers

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.

like image 60
jkysam Avatar answered Dec 08 '25 17:12

jkysam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!