private async void ProcessSocket(Socket socket) { Logger.Write("Connected from: " + socket.RemoteEndPoint); var session = new PacketSession(socket); _lock.DoWriteLock(() => _sessions.Add(session)); Dispatch(new ConnectionPacket { Connected = true }, session); try { while (true) { var packet = await session.Receive(); Dispatch(packet, session); } } catch (Exception e) { Logger.Write(e); } Dispatch(new ConnectionPacket { Connected = false }, session); _lock.DoWriteLock(() => _sessions.Remove(session)); try { socket.Shutdown(SocketShutdown.Both); } catch { } }
public void AddSocket(Socket socket) { _lock.DoWriteLock(() => _sockets.Add(socket, SocketInformation.Invalid)); }