Пример #1
0
        private void OnSent(object sender, Socket socket, SocketMessage message)
        {
            string dataString = Encoding.UTF8.GetString(message.Body);

            txtLog.Invoke(new Action(() =>
            {
                txtLog.AppendText($"Sent to [{socket.RemoteEndPoint}]---->\r\n Key:{message.Key}\r\n Lehgth:{message.Length}\r\n Body: {dataString}\r\n");
            }));
        }
Пример #2
0
 private void btnSend_Click(object sender, EventArgs e)
 {
     if (txtMsg.Text.Trim() == string.Empty)
     {
         txtLog.AppendText("Cannot send an empty message ...\r\n");
     }
     else
     {
         byte[]        bodyBytes = Encoding.UTF8.GetBytes(txtMsg.Text.Trim());
         SocketMessage message   = new SocketMessage {
             Key = Guid.NewGuid(), Length = bodyBytes.Length, Body = bodyBytes
         };
         _socketClient.Send(message);
     }
 }