示例#1
0
 public void CallBroker(uint callId, string jsonData, int cmdId)
 {
     Logger.DEBUG(string.Empty);
     try
     {
         PendingRequest pendingRequest = new PendingRequest();
         pendingRequest.createTime = Utils.NowSeconds();
         pendingRequest.seqNo      = callId;
         Dictionary <string, object> dictionary = new Dictionary <string, object>();
         UserData userData = Pandora.Instance.GetUserData();
         dictionary.set_Item("seq_id", callId);
         dictionary.set_Item("cmd_id", cmdId);
         dictionary.set_Item("type", 1);
         dictionary.set_Item("from_ip", "10.0.0.108");
         dictionary.set_Item("process_id", 1);
         dictionary.set_Item("mod_id", 10);
         dictionary.set_Item("version", Pandora.Instance.GetSDKVersion());
         dictionary.set_Item("body", jsonData);
         dictionary.set_Item("app_id", userData.sAppId);
         string text   = Json.Serialize(dictionary);
         string text2  = MinizLib.Compress(text.get_Length(), text);
         byte[] array  = Convert.FromBase64String(text2);
         int    num    = IPAddress.HostToNetworkOrder(array.Length);
         byte[] bytes  = BitConverter.GetBytes(num);
         byte[] array2 = new byte[bytes.Length + array.Length];
         Array.Copy(bytes, 0, array2, 0, bytes.Length);
         Array.Copy(array, 0, array2, bytes.Length, array.Length);
         pendingRequest.data = array2;
         this.brokerPendingRequests.Enqueue(pendingRequest);
     }
     catch (Exception ex)
     {
         Logger.ERROR(ex.get_StackTrace());
     }
 }
示例#2
0
 private void AsynCallBroker(Socket socket, string message)
 {
     if (socket == null || message == string.Empty)
     {
         return;
     }
     Debug.Log(string.Empty);
     try
     {
         int num = 9000;
         Dictionary <string, object> dictionary = new Dictionary <string, object>();
         dictionary.set_Item("seq_id", 1);
         dictionary.set_Item("cmd_id", num);
         dictionary.set_Item("type", 1);
         dictionary.set_Item("from_ip", "10.0.0.108");
         dictionary.set_Item("process_id", 1);
         dictionary.set_Item("mod_id", 10);
         dictionary.set_Item("version", this.kSDKVersion);
         dictionary.set_Item("body", message);
         dictionary.set_Item("app_id", this.userData.get_Item("sAppId"));
         string text   = Json.Serialize(dictionary);
         string text2  = MinizLib.Compress(text.get_Length(), text);
         byte[] array  = Convert.FromBase64String(text2);
         int    num2   = IPAddress.HostToNetworkOrder(array.Length);
         byte[] bytes  = BitConverter.GetBytes(num2);
         byte[] array2 = new byte[bytes.Length + array.Length];
         Array.Copy(bytes, 0, array2, 0, bytes.Length);
         Array.Copy(array, 0, array2, bytes.Length, array.Length);
         IAsyncResult asyncResult     = socket.BeginSend(array2, 0, array2.Length, 0, null, null);
         WaitHandle   asyncWaitHandle = asyncResult.get_AsyncWaitHandle();
         try
         {
             if (!asyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds((double)this.sendRcvTimeOut)))
             {
                 Debug.Log("Send Time Out:" + this.sendRcvTimeOut.ToString());
                 this.CloseSocket(socket);
             }
             else
             {
                 try
                 {
                     int num3 = socket.EndSend(asyncResult);
                     if (asyncResult.get_IsCompleted() && num3 == array2.Length)
                     {
                         Debug.Log(string.Format("客户端发送消息:{0}", text));
                         this.AsynRecive(socket);
                     }
                     else
                     {
                         this.CloseSocket(socket);
                     }
                 }
                 catch (Exception ex)
                 {
                     Debug.Log(ex.get_Message());
                     this.CloseSocket(socket);
                 }
             }
         }
         catch (Exception ex2)
         {
             Debug.Log(ex2.get_Message());
             this.CloseSocket(socket);
         }
         finally
         {
             asyncWaitHandle.Close();
         }
     }
     catch (Exception ex3)
     {
         Debug.Log(string.Format("异常信息:{0}", ex3.get_Message()));
         this.CloseSocket(socket);
     }
 }