Best Socket Options for Client and Partition That Continuously Transfer Data

I use Java (although I think the socket options are implemented in most languages) to implement the client and server. The server sends data to the client for processing, which the client confirms. On another port, the client sends the processing results back to the server. When it comes to options like

  • SO_LINGER
  • SO_KEEPALIVE
  • SO_NODELAY
  • SO_REUSEADDRESS
  • SO_SENDBUFFER
  • SO_RECBUFFER
  • TCP_NODELAY

We noticed that the connection between the client and server breaks from time to time. There will be a waiting time for sending or receiving. When this happens, kill the socket and open a new one to continue.

What will be the best options for determining, taking into account the above scenario, and is there anything that we could do on our part (programmatically or in different ways) to try to minimize the number of disconnections of the connection. We use regular TCP / IP.

UPDATE: It will come soon. I have not yet had a satisfactory answer, but it is still open. I think that everyone does not have the goal of the quest. What is the best practice regarding the above options for sockets that are constantly chatting. I already have a ping package in case there is no work (hardly ever in the script), a normal message is sent without internal elements, so processing is always performed.

+3
source share
6 answers

, - :

* SO_LINGER

SO_LINGER , - close(2) shutdown(2). .

* SO_KEEPALIVE

keepalive-pings , , - . ( , .)

* SO_NODELAY

( TCP_NODELAY) Nagle, . , Nagle , 500 ; .

* SO_REUSEADDRESS

"", ; "" , , .

* SO_SENDBUFFER
* SO_RECBUFFER

, , ( ) ( ) . , , , , - , . , , .

* TCP_NODELAY

Nagle. , 500 , .

, - .

-, ? TCP, , .

+6

, . http://nitoprograms.blogspot.com/2009/05/detection-of-half-open-dropped.html

TCP , , , . , , .

, TCP, , . , . , , ack'd, - ack. , - ack . - (, , , , ).

, , SO_REUSEADDRESS, , , .

+2

, , ....

, , , ? , , -, , . , .

, , , , , " " , , ?

, , , , .

+1

SO_LINGER - , Socket close s , TCP_NODELAY -

0

ping/echo , , x , ping. , - .
, TCP , . / , - , ( ).

0

, NAT - ? , , , , .

, , , , , . , 20 , , . ( , TCP KEEPALIVE , NAT.)

So: does this happen through the NAT firewall? Is the connection quiet for long sections? If so, add ping / pong to your protocol and run it every few minutes.

0
source

Source: https://habr.com/ru/post/1753484/


All Articles