Hey there,
I have a client/server architecture going here where my client creates an extended TcpClient object (I extended it so I could use an underlying socket since I need to specify the local port) every so-often and the polls the server for data. Now, when it does this polling, it's only sending back and forth short strings and small numbers. If it finds no "significant" data (that is, other than the short strings and numbers), it waits another interval, then polls again, etc.
Now, if it DOES find "significant" data, it reads it in, shuts down the connection and sockets; then my client deals with the data just fine, and sends back the results to the server using another extended TcpClient object to a different remote port. This works wonderfully, and then shuts down.
HOWEVER...The NEXT time it tries to poll with said extended TcpClient object, I get this SocketException:
"Only one usage of each socket address (protocol/network address/port) is normally permitted"
...and it's generated from the Connect method of the Socket. Now, I've set the following socket options:
- ReuseAddress
- DontLinger
- NoDelay
(I set them all to 1.)
The ONLY way this exception doesn't happen is if I wait 2 minutes or longer; this is unacceptable. Now, this would lead me to believe that it's an issue with data being left over in the stream or one of the sockets (local or remote) not being disposed of quick enough--but it's probably some combination of the two, since if the polling client finds no "significant" data, whenever it polls again, it creates the Socket again just fine. But the first time the "significant" data is picked up and processed, each subsequent poll will fail (ie. the socket will not connect). I've checked the "data available" properties and what not and they're all empty after I close the socket (I call "shutdown" first and then "close"). So I'm lost!
Can anyone lend me a hand here? This is really obnoxious.
Cheers,
Duncan
