Designing a High Performance TCP Client

I have a .NET TCP client that sends large volumes of messages to a TCP server (.NET async).

I need to continue sending messages to the server, but because of TIME_WAIT, I have run out of ports on the client.

How can a program constantly and reliably send messages without using all available ports?

Is there a way to reuse the same socket. I looked at Disconnect () and the REUSEADDRESS socket flag, but did not find any good examples of their use. In fact, most sources claim that not using Disconnect is the same as for a lower level of use (i.e., it only processes the socket descriptor).

I think I need to switch to UDP or maybe there is a method using C ++ and IOCP?

+3
source share
6 answers

You can leave the socket open if your server and client know the data format. You close the socket so that the server can “see” that the client is “done”.

If you have a protocol, then the server can “know” when it has finished receiving the data block.

You can find somekind message end token, you can pass the message length and read the rest based on size, etc. Different ways to do this.

But there is no reason to constantly open and close connections to the server - which kills you here.

+5
source

Can your client just keep the same socket open and send messages in a loop?

open socket connection

while(running)
    send messages over socket

close socket connection
+1
source

TCP . TCP- " ", . ACK , TCP , .., .

, TCP-. , , . , TCP- .

( ). HTTP- , ; , - , "" HTTP 1.1, HTTP TCP-.

- UDP. , , , - , - . , UDP, , .

+1

.

.

, , .

, , .

, Async .NET. MSDN .

0

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

Google MSDN #.

0

TCP- ( ) - , .

open a server socket // this uses the port the clients know about

while(running)
    client_socket = server_socket.listen
    fork(new handler_object(client_socket))

#.

0
source

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


All Articles