When my client application launchs, it binds the UDP port like this:
this.BindPort(5001);
The BindPort method implement blow:
public void BindPort(int port)
{
m_listener = new Socket( AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp );
IPEndPoint Point = new IPEndPoint( IPAddress.Any, Port );
m_listener.Bind( port);
m_listener.BeginReceive( buff, 0, buff.Length, SocketFlags.None,
new AsyncCallback( DataReceived ), buff );
}
And when my server application commands client to bind to another UDP port(e.g. 5005). I call the same BindPort method in client. Then a exception occurs at DataReceived method.
I think there must be a problem that I don't close the UDP port properly.
But how can i close the UDP socket properly and rebind to another one.
Thanks.