/// <summary> /// Processes the connection. /// </summary> public void ProcessConnection() { try { var dataBuffer = new byte[65536]; while (true) { int byteCount = socket.Receive(dataBuffer); if (byteCount > 0) { DataAssembler.Deserialize(dataBuffer, 0, byteCount); } } } catch (IOException e) { Console.Error.WriteLine("Error receiving data from client. Did client disconnect?"); Console.Error.WriteLine("Error message: {0}", e.Message); Console.Error.WriteLine(e.StackTrace); } finally { socket.Close(); RemoveSelf(); StatsHolder.Remove(StatsHolder.Engine); StatsHolder.Remove(StatsHolder.Server); StatsHolder.Remove(StatsHolder.EndToEnd); } }
/// <summary> /// Receives the callback. /// </summary> /// <param name="ar">The ar.</param> private void ReceiveCallback(IAsyncResult ar) { try { SocketError errorCode; var bytesReceived = _socket.EndReceive(ar, out errorCode); if (bytesReceived > 0) { DataAssembler.Deserialize(_dataArray, 0, bytesReceived); } } catch (IOException e) { Console.Error.WriteLine("Error receiving data from client. Did client disconnect?"); Console.Error.WriteLine("Error message: {0}", e.Message); Console.Error.WriteLine(e.StackTrace); } _socket.BeginReceive(_dataArray, 0, _dataArray.Length, SocketFlags.None, ReceiveCallback, null); }