Q:

Design of high volume TCP Client

I have a .NET TCP Client that sends high volumes of messages to a (.NET async) TCP server.
I need to keep sending messages to the server but I run out of ports on the client due to TIME_WAIT.  
How can a program continually and reliably send messages without using all of the available ports?
Is there a method to keep reusing the same socket.  I have looked at Disconnect() and the REUSEADDRESS socket flag but cannot find any good examples of their use.  In fact most sources say not to use Disconnect as it is for lower level use (i.e. it only recycles the socket handle).
I'm thinking that I need to switch to UDP or perhaps there is a method using C++ and IOCP?

A:

You can keep the socket open if your server and client are aware of the format of the data. You're closing the socket so that the server can "see" that the client is "done".
If you have some protocol, then the server can "know" when it's finished receiving a block of data.
You can look for an End-of-message token of somekind, you can pass in the length of the message, and read the rest based on size, etc. Different ways of doing it.
But there's no reason to constantly open and close connections to the server -- that's what's killing you here.

