Пример #1
0
 /// <summary>
 /// General send method
 /// </summary>
 public void SendText(string text)
 {
     if (!string.IsNullOrEmpty(text))
     {
         try
         {
             var bytes = Encoding.GetEncoding(28591).GetBytes(text);
             if (Client != null && Client.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED)
             {
                 Client.SendDataAsync(bytes, bytes.Length, (c, n) =>
                 {
                     // HOW IN THE HELL DO WE CATCH AN EXCEPTION IN SENDING?????
                     if (n <= 0)
                     {
                         Debug.Console(1, Debug.ErrorLogLevel.Warning, "[{0}] Sent zero bytes. Was there an error?", this.Key);
                     }
                 });
             }
         }
         catch (Exception ex)
         {
             Debug.Console(0, this, "Error sending text: {1}. Error: {0}", ex.Message, text);
         }
     }
 }
Пример #2
0
 internal void ClientSendDataAsync(byte[] data)
 {
     if (EnableSSL)
     {
         SSLClient.SendDataAsync(data, data.Length, ClientSendSSLCallback);
     }
     else
     {
         NoSSLClient.SendDataAsync(data, data.Length, ClientSendNoSSLCallback);
     }
 }
 // Asynchronously send an ASCII string of text to the server. clientSendCallback will fire
 // when the message is sent, or if an error occurs
 public void SendMessage(string message)
 {
     if (client == null || client.ClientStatus != SocketStatus.SOCKET_STATUS_CONNECTED)
     {
         CrestronConsole.PrintLine("You must connect the client to a server before sending data! See the connect user command.");
         return;
     }
     byte[] message_buf;
     try
     {
         // You can use whatever encoding you require. This example uses the ASCII encoding
         message_buf = ASCIIEncoding.ASCII.GetBytes(message);
         SocketErrorCodes err = client.SendDataAsync(message_buf, message.Length, clientSendCallback);
         PrintAndLog("SendDataAsync returned: " + err);
     }
     catch (Exception e)
     {
         PrintAndLog("Error sending message: " + e.Message);
     }
 }
Пример #4
0
 public void Send(MqttMsgBase packet)
 {
     CrestronLogger.WriteToLog("MQTTCLIENT - SEND - Sending packet :" + packet, 2);
     byte[] pBufferToSend = packet.GetBytes(ProtocolVersion);
     tcpClient.SendDataAsync(pBufferToSend, pBufferToSend.Length, SendCallback);
 }