L
L.J.SONG
I use following code to create socket and connect to a server app:
/// code /////
Socket connecter = null;
IPEndPoint localEp = null;
IPEndPoint remoteEp = null;
IPHostEntry he = Dns.Resolve("localhost");
IPAddress localAddr = he.AddressList[0];
localEp = new IPEndPoint(localAddr,11000);
remoteEp = new IPEndPoint(localAddr,8801);
connecter = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
connecter.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.DontLing
er,1);
try
{
connecter.Bind(localEp);
}
catch(SocketException se)
{
}
connecter.Connect(remoteEp);
connecter.Shutdown(SocketShutdown.Both);
connecter.Close();
//////////
These code could connected to server,
but when I close it and then run it second time .It throw a exception
told me that the port still be bounded and can't be use again.
use "netstat" command I can find the port still keep close_wait state
and this state will keep 3-5 minute.
Who can tell me why and how to make this port release immediately?
Thanks alot.
/// code /////
Socket connecter = null;
IPEndPoint localEp = null;
IPEndPoint remoteEp = null;
IPHostEntry he = Dns.Resolve("localhost");
IPAddress localAddr = he.AddressList[0];
localEp = new IPEndPoint(localAddr,11000);
remoteEp = new IPEndPoint(localAddr,8801);
connecter = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
connecter.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.DontLing
er,1);
try
{
connecter.Bind(localEp);
}
catch(SocketException se)
{
}
connecter.Connect(remoteEp);
connecter.Shutdown(SocketShutdown.Both);
connecter.Close();
//////////
These code could connected to server,
but when I close it and then run it second time .It throw a exception
told me that the port still be bounded and can't be use again.
use "netstat" command I can find the port still keep close_wait state
and this state will keep 3-5 minute.
Who can tell me why and how to make this port release immediately?
Thanks alot.