How to reuse a socket ? (Socket in use error)

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Hi,

I browsed the news and a few seem to have this problem too, but no
solution !

I have a client server application where in case the connection gets bad
(crashes or whatever) client or server (who knows it first) closes the
socket and than wants to establish the SAME connection again ( due to
firewall reasons it has to be the SAME IP AND PORT).

Whatever I do, after close and trying to listen again, binding on the
local IPPort gets me the "connection in use error".

I use shutdownboth, close I use lingeroption with false and 0, I tried
to calle GC after close, I even tried to call socket.Dispose via reflection.

I can see in debug window, that socket is closed and cleaned up is set
to true and the local and remote endpoint properties are NULL, BUT there
is aa local ippoint member still active.

So how the hell can I clean up that socket to reconnect ??

I tried the UseSameAdress option, i dont get the socket in use
exception, but than no event is fired when the client connects (begin
accept delegate not fired), so obviously the clients seem to connect to
the dead socket somehow.

Any help please !

Joe Robe
 
I had a similar problem before. In my case, as long as the client didn't
reuse the same port (in other words, use an ephemeral port as opposed to
specifying an actual port for the client), I had no problem reconnecting to
the same server port. I assume the firewall problem only exists on the
server side. Hope that helps. It's been a while so there may be details that
I'm not recalling.

-Christine
 
Back
Top