Example #1
0
 /*
 public void onMessage(WebSocketConnection connection, bool final, bool res1, bool res2, bool res3, int code, MemoryStream data)
 {
     // Deserialise it once to get its type
     Message message;
     try
     {
         message = GetMessage(data, final, code);
         if (message == null)
         {
             return;
         }
     }
     catch (Exception e)
     {
         Logger.Error("Failed to process message from json into an object : " + e.Message);
         return;
     }
     ProcessMessage(message);
 }
  */
 private void ProcessMessage(Message message)
 {
     if (message is API.Response)
     {
         WebSocketClient.ProcessResponse((API.Response) message);
     }
     else if (message is API.Request)
     {
         WebSocketServer.ProcessRequest((API.Request) message);
     }
     else
     {
         Logger.Error("Failed to determine message type for message " + message.id);
     }
 }
Example #2
0
 public void SendMessage(Message message)
 {
     DataContractJsonSerializer ser = new DataContractJsonSerializer(message.GetType());
     MemoryStream stream = new MemoryStream();
     ser.WriteObject(stream, message);
     String resAsString = Encoding.UTF8.GetString(stream.ToArray());
     _connection.SendText(resAsString);
     if (!Regex.Match(resAsString, "\"type\":\"Ping").Success)
     {
         Logger.Debug("Sent message : " + SanitiseMessage(resAsString));
     }
 }