public void Handle() { var newSocket = ServerSocket.handle(); if (newSocket != null) { //Wrap socket in a RPC ping handler var router = new NetworkSocketStateRouter(); var socketId = SocketIdCounter.Get(); SocketRoutes.Add(socketId, router); Sockets.Add(socketId, newSocket); onConnected(socketId, newSocket, router); } List <int> timed = new List <int>(); foreach (var pair in Sockets) { pair.Value.handle(); while (true) { var msg = pair.Value.getMessage(); if (msg != null) { BinaryReader reader = new BinaryReader(new MemoryStream(msg)); uint cmd = reader.ReadUInt32(); SocketRoutes[pair.Key].Handle(this, pair.Key, cmd, reader); } else { break; } } } }