public void Listen(ushort port)
{
try
{
if (!Listening)
{
_clients = new List<Client>();
_item = new SocketAsyncEventArgs();
_item.Completed += Process;
_handle = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//_handle.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
_handle.Bind(new IPEndPoint(IPAddress.Any, port));
_handle.Listen(10);
Processing = false;
Listening = true;
OnServerState(true);
if (!_handle.AcceptAsync(_item))
Process(null, _item);
}
}
catch
{
Disconnect();
}
}