private async void PacketPump() { try { _session.Connect(_host, _port); _connected = true; while (true) { var packet = await _session.Receive(); Invoke( new MethodInvoker( () => _dispatcher.Dispatch(packet, _session))); } } catch { } _connected = false; }
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 { } }