// This method is invoked when an asynchronous receive operation completes. // If the remote host closed the connection, then the socket is closed. // If data was received then the data is echoed back to the client. // private void ProcessReceive(SocketAsyncEventArgs e) { // check if the remote host closed the connection AsyncUserToken token = (AsyncUserToken)e.UserToken; if (e.BytesTransferred > 0 && e.SocketError == SocketError.Success) { //increment the count of the total bytes receive by the server Interlocked.Add(ref m_totalBytesRead, e.BytesTransferred); string msg = m_bufferManager.GetMessageInBuffer(e); // Debug.Log("(1) received: '" + msg + "' : The server has read a total of " + m_totalBytesRead + " bytes"); ProcessClientMessage(e, token, msg); } else { CloseClientSocket(e); } }