Specifying TcpClient LocalEndpoint yeilds 10048 error

T

TDC

I've got an HttpHandler that creates a TcpClient, connects to a server
to exchange some data, and then disconnects.

The problem is I am eventually getting SocketExceptions [Only one
usage of each socket address (protocol/network address/port)is
normally permitted].

After doing some research, I've discovered that I was exhausting the
default range of local ports being dished out to the TcpClient
objects, and instead I implemented assigning the Local Endpoint
manually so I could increment the local port number myself.

As the Local Address, Remote Address, and Remote Port are all fixed,
the local port is the field I have to work with to create unique
connections.

The solution drastically improved the success rate, but I'm still
occasionally getting address-in-use errors. As long as my previous
usage of the local port has gone through its TIME_WAIT period, I
should be able to use that port number again, AFAIK.

Has anyone hit this issue before? Any hinst as to why the
SocketExceptions still persist is appreciated!
 
T

TDC

I suppose that some other program/process may have grabbed the port
number. I'm explicitly allocating from above the top default range
(5000+) but I guess some other app might be doing so as well?
 
T

TDC

I started with using 0, but ran out of ports quite quickly. After
some research, I found that there are system tcp registry settings
that control the "user range" of ephemeral ports, and that the default
is 1024 to 5000.

See http://blogs.msdn.com/dgorti/archive/2005/09/18/470766.aspx

I'd be greatful for a better solution than just trying to Bind or
local ports until I find a good one, if anyone has an idea.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top