K
K
kodwi2015-11-17 13:05:51
C++ / C#
kodwi, 2015-11-17 13:05:51

How to immediately completely close the socket at TcpClient, without a timeout and release the port in the system?

TcpClient server = new TcpClient();
server.Client.LingerState = new LingerOption(false, 0);
server.NoDelay = true;
....
server.Client.Shutdown(SocketShutdown.Both);
server.Close();
server = null;

And after that, all the same, for about 30 seconds, netstat shows TIMEW on the port that was used by the tcp client, and it is impossible to connect. But at the same time, if the application is immediately closed, then it becomes possible to connect again on this port, without a timeout.
As I understand it, the connection breaks, but the system still holds the port during the timeout. How to tell the system to immediately release the port?
PS Windows 10 OS.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2015-11-17
@Nipheris

on the port used by the tcp client

I don't understand what you are doing at all. Are you specifying a fixed client port number? How and why?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question