Make sure to dispose of old Socket

Made sure the server disposed of the Socket when Server.Listen(ushort)
is called if the Socket was created before (called Server.Listen(ushort)
previously but stopped listening).
This commit is contained in:
yankejustin 2015-04-07 12:27:56 -04:00
parent 539a9b3d5b
commit b927aae0f8
1 changed files with 10 additions and 0 deletions

View File

@ -94,6 +94,16 @@ public void Listen(ushort port)
_item = new SocketAsyncEventArgs(); _item = new SocketAsyncEventArgs();
_item.Completed += Process; _item.Completed += Process;
if (_handle != null)
{
try
{
_handle.Close();
}
catch
{ }
}
_handle = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _handle = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_handle.Bind(new IPEndPoint(IPAddress.Any, port)); _handle.Bind(new IPEndPoint(IPAddress.Any, port));