Opc.Ua.NetworkTester.Server.OnReadFromClient C# (CSharp) Method

OnReadFromClient() private method

Called to complete an asynchronous read operation.
private OnReadFromClient ( IAsyncResult result ) : void
result IAsyncResult
return void
        private void OnReadFromClient(IAsyncResult result)
        {
            // find the connection.
            Connection connection = result.AsyncState as Connection;

            if (connection == null || !connection.IncomingSocket.Connected)
            {
                return;
            }

            try
            {
                // complete read.
                int bytesReceived = connection.IncomingSocket.EndReceive(result);   

                if (bytesReceived == 0)
                {                    
                    Close(connection);
                    return;
                }

                connection.OutgoingSocket.Send(connection.ClientToServerBuffer, 0, bytesReceived, SocketFlags.None);
                      
                // start read from client.                
                connection.IncomingSocket.BeginReceive(
                    connection.ClientToServerBuffer,
                    0,
                    connection.ClientToServerBuffer.Length,
                    SocketFlags.None,
                    OnReadFromClient,
                    connection);
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error reading from client.");
                Close(connection);
            }
        }