Beispiel #1
0
 /// <summary>
 /// Method responsible for execute the callback of message received from server in client.
 /// </summary>
 /// <param name="kingBuffer">The king buffer from received message.</param>
 private static void OnMessageReceived(IKingBuffer kingBuffer)
 {
     try
     {
         _messagesReceived++;
         _dataReceived += kingBuffer.Length();
         _bufferLength  = kingBuffer.Length();
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error: {ex.Message}.");
     }
 }
 /// <summary>
 /// Method responsible for send message to connected server.
 /// </summary>
 /// <param name="kingBuffer">The king buffer of received message.</param>
 public override void SendMessage(IKingBuffer kingBuffer)
 {
     try
     {
         _stream.BeginWrite(kingBuffer.ToArray(), 0, kingBuffer.Length(), null, null);
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error: {ex.Message}.");
     }
 }
Beispiel #3
0
        /// <summary>
        /// Method responsible for execute the callback of message received from client in server.
        /// </summary>
        /// <param name="client">The client instance.</param>
        /// <param name="kingBuffer">The king buffer from received message.</param>
        private static void OnMessageReceived(IClient client, IKingBuffer kingBuffer)
        {
            try
            {
                _server.SendMessage(client, kingBuffer);

                _messagesReceived++;
                _dataReceived += kingBuffer.Length();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}.");
            }
        }
Beispiel #4
0
 /// <summary>
 /// Method responsible for send message to client.
 /// </summary>
 /// <param name="kingBuffer">The king buffer of received message.</param>
 public void SendMessage(IKingBuffer kingBuffer)
 {
     try
     {
         if (IsConnected)
         {
             _stream.Write(kingBuffer.ToArray(), 0, kingBuffer.Length());
             _stream.Flush();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error: {ex.Message}.");
     }
 }