示例#1
0
 public void HandleNetworkMessageJson(Messages.BaseMsg msg)
 {
     if (msg.Type != "Cmd")
     {
         return;                    // this is not a command msg
     }
     Messages.Cmd cmd = (Messages.Cmd)msg;
     if (!functions.ContainsKey(cmd.cmd))
     {
         return;                            // we dont have a comand with this name
     }
     functions[cmd.cmd].Callback(cmd.args); // exec cmd
 }
示例#2
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            try{
                StringBuilder sb = (StringBuilder)ar.AsyncState;
                // Read data from the remote device.
                int bytesRead = client.EndReceive(ar);

                // There might be more data, so store the data received so far.
                sb.Append(Encoding.UTF8.GetString(revBuffer, 0, bytesRead));
                if (bytesRead == revBuffer.Length)
                {
                    //  Get the rest of the data.
                    client.BeginReceive(this.revBuffer, 0, this.revBuffer.Length, 0,
                                        new AsyncCallback(ReceiveCallback), sb);
                    return;
                }
                else
                {
                    // All the data has arrived; put it in response.
                    Receive();
                    if (sb.Length > 1)
                    {
                        string msg = sb.ToString();
                        try
                        {
                            //dynamic msgJson = RemoteConsole.DynamicJson.Parse(msg);
                            Messages.BaseMsg msgJson = Messages.MessageHandler.getMessage(msg);
                            Debug.Log(msgJson);
                            switch (msgJson.Type) // check if we have a special purpos for msg this this prefix
                            {
                            case "AuthAsw":
                                this.Send(this.functions.getListFroNetwork());
                                break;

                            default:     // no special porpos add to basic queue
                                stackDynamic.Enqueue(msgJson);
                                break;
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.LogError("can not parse Json" + e);
                        }
                    }
                }
            }catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        if (client == null)
        {
            return;
        }
        string str = client.getMessage(); // Message resived from Network

        if (str != null)                  // check if we have a valide msg
        {
            HandleNetworkMessage(str);
        }

        RemoteConsole.Messages.BaseMsg msg = client.getMessageDynamic(); // Message resived from Network
        if (msg != null)                                                 // check if we have a valide msg
        {
            //HandleNetworkMessageJson(jsonMsg);
            FUNCTIONS.HandleNetworkMessageJson(msg);
        }
    }
示例#4
0
        static public BaseMsg getMessage(string Json)
        {
            BaseMsg msgJson = JsonUtility.FromJson <BaseMsg>(Json);

            return((BaseMsg)JsonUtility.FromJson(Json, msgJson.GetMsgType()));
        }