Hi,
I
currently have an app that spawns a connection to server, the server
requires hard IP and Port for both my app and the server itself. It
then sends a command and disconnects. The problem is that I have to
wait ~5 minutes for the socket to become usable again. I know that
windows likes to maintain the socket for a few minutes. Any idea on
how I can get around this. I call the socket.close() method when I am
done sending my parameters. I tried setting
socket.setSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true)
but
it does not seem to release the socket fast enough (still taking ~5 minutes) for me to spawn new
connections. The hard IP and port can not be changed (unfortunatly for
me). Does anyone know of a way to drop a socket connection and release
the resources immediatly so I can bind a new socket and send another
command Thanks for your help
Tom

socket not released
CarlosLh
OldSchoolJohn
Yeah, that is too bad. I would try to contact the software vender and try to understand their requirment better. There really is no added security for the server by requiring a client to connect from a specific port (I can understand the IPAddress requirement though).
Does the server allow you to reuse the connection for more than a short period of time Do you absolutely have to close the connection so frequently
neiden
olunow
From a command prompt, type "netstat -a -o -p tcp", which will print out all of the tcp sockets that are either in use or in the TIME_WAIT state. What do you see Are there a bunch of sockets in the TIME_WAIT state If so, read http://blogs.msdn.com/dgorti/archive/2005/09/18/470766.aspx.
If this is not the error you are seeing, please post the exception message and stack trace.
ARok
Unfortunately thats how the TCP protocol works.
I would say that in general you should let the client choose the port
that is dynamic and available. The server is the one that should bind to the same post always.
If you look at my blog
http://blogs.msdn.com/dgorti
You will see some ideas on how to do this
January
Well, you probably need to do some analysis as to the actual amount of data on the network. If you are reconnecting often, the network traffic of establishing the connection may be more than the overhead of keeping the connection alive. Also, if I remember right, the sending of keepalive packets is something you opt into (not on by default), so the cost of keeping the connection alive may not be as bad as you think. You will have to do your own analysis to make sure, but I think it is worth the effort in this case.
Of course, this all depends on whether the server will even allow you to keep the connection alive...
Schilm
WillySnowMan
Can you describe why the client has to connect from a specific port It seems to me like you have a design flaw.
Forestc