コード例 #1
0
    public static void OnQuery(Message msg)
    {
        var result = msg.jsonObj;

        if (Convert.ToInt32(result["code"]) == 200)
        {
            pomeloClient.Disconnect();

            string host = (string)result["host"];
            int    port = Convert.ToInt32(result["port"]);
            pomeloClient = new PomeloClient();

            pomeloClient.On(PomeloClient.DisconnectEvent, jsonObj =>
            {
                Console.WriteLine(pomeloClient.netWorkState);
            });

            pomeloClient.InitClient(host, port, jsonObj =>
            {
                pomeloClient.Connect(null, (data) =>
                {
                    //MessageObject userMessage = new MessageObject();
                    Console.WriteLine("on connect to connector!");

                    //Login
                    MessageObject enterMsg = new MessageObject();
                    enterMsg["userName"]   = "******";
                    enterMsg["rid"]        = "pomelo";

                    pomeloClient.Request("connector.entryHandler.enter", enterMsg, OnEnter);
                });
            });
        }
    }
コード例 #2
0
ファイル: ChatGUI.cs プロジェクト: sfszh/pomelo-unitychat
    void Start()
    {
        chatRecords = new ArrayList();
        userList    = new ArrayList();
        chatWindow  = new Rect(0, 0, Screen.width - 150, Screen.height);
        usersWindow = new Rect(Screen.width - 150, 0, 200, Screen.height);
        pomelo_label_Style.normal.textColor = Color.black;

        InitUserWindow();

        pclient.On("onAdd", (data) => {
            RefreshUserWindow("add", data);
        });

        pclient.On("onLeave", (data) => {
            RefreshUserWindow("leave", data);
        });

        pclient.On("onChat", (data) => {
            addMessage(data);
        });
    }
コード例 #3
0
    // Use this for initialization
    void Start()
    {
        JsonObject jsonConfig = ReadFromJsonFile("./server.json");
        string szURL = (string)jsonConfig["host"];
        m_PomeloClient = new PomeloClient(szURL);
        m_PomeloClient.init();

        string szRoute = "connector.entryHandler.entry";
        m_PomeloClient.On(szRoute, (data) =>
        {
            Debug.Log(data.ToString());
        });
        Debug.Log("Pomelo client init.");
    }
コード例 #4
0
    void Start()
    {
        pomeloClient = new PomeloClient();

        IPInput.text       = "localhost";
        NameInput.text     = "spark";
        PasswordInput.text = "123456";

        pomeloClient.On("onTick", msg =>
        {
            _onResponseRet(msg);
        });

        //listen on network state changed event
        pomeloClient.On(PomeloClient.DisconnectEvent, msg =>
        {
            Debug.logger.Log("Network error, reason: " + msg.jsonObj["reason"]);
        });

        pomeloClient.On(PomeloClient.ErrorEvent, msg =>
        {
            Debug.logger.Log("Error, reason: " + msg.jsonObj["reason"]);
        });
    }
コード例 #5
0
    public static void loginTest(string host, int port)
    {
        pomeloClient = new PomeloClient();

        //listen on network state changed event
        pomeloClient.On(PomeloClient.DisconnectEvent, jsonObj =>
        {
            Console.WriteLine("CurrentState is:" + pomeloClient.netWorkState);
        });

        pomeloClient.InitClient(host, port, jsonObj =>
        {
            pomeloClient.Connect(null, data =>
            {
                Console.WriteLine("on data back" + data.ToString());
                MessageObject msg = new MessageObject();
                msg["uid"]        = 111;
                pomeloClient.Request("gate.gateHandler.queryEntry", msg, OnQuery);
            });
        });
    }
コード例 #6
0
ファイル: JoviosNetworking.cs プロジェクト: Ar2rZ/Cards
    public void NodeLinux()
    {
        string url = "54.186.22.19:3014";

        if (!has_internet)
        {
            has_internet = CheckForServerConnection();
            if (!has_internet)
            {
                Debug.Log("no internet connection");
                return;
            }
        }
        if (pclient != null)
        {
            Disconnect();
        }
        pclient = new PomeloClient(url);
        pclient.init();
        JsonObject userMessage = new JsonObject();

        userMessage.Add("uid", parser.GetDeviceID());
        pclient.request("gate.gateHandler.queryEntry", userMessage, (data) => {
            System.Object code = null;
            if (data.TryGetValue("code", out code))
            {
                if (Convert.ToInt32(code) == 500)
                {
                    return;
                }
                else
                {
                    pclient.disconnect();
                    pclient = null;
                    System.Object host, port;
                    if (data.TryGetValue("host", out host) && data.TryGetValue("port", out port))
                    {
                        pclient = new PomeloClient("http://" + "54.186.22.19" + ":" + port.ToString());
                        pclient.init();
                        pclient.On("onAdd", (data3) => {
                            Dictionary <string, object> packet = Json.Deserialize(data3.ToString()) as Dictionary <string, object>;
                            Dictionary <string, object> body   = (Dictionary <string, object>)packet["body"];
                            parser.OnAdd((string)body["user"]);
                        });
                        pclient.On("onChat", (data2) => {
                            Dictionary <string, object> packet = Json.Deserialize(data2.ToString()) as Dictionary <string, object>;
                            Dictionary <string, object> body   = (Dictionary <string, object>)packet["body"];
                            AddMessage((string)body["msg"]);
                        });
                        pclient.On("onLeave", (data4) => {
                            Dictionary <string, object> packet = Json.Deserialize(data4.ToString()) as Dictionary <string, object>;
                            Dictionary <string, object> body   = (Dictionary <string, object>)packet["body"];
                            parser.OnLeave((string)body["user"]);
                        });
                        pclient.On("onError", (data5) => {
                            System.Object nodeLinuxError;
                            data5.TryGetValue("body", out nodeLinuxError);
                            Debug.Log(nodeLinuxError.ToString());
                        });
                        if (parser.GetGameCode() == "" || parser.GetGameCode() == null)
                        {
                            NewGame();
                        }
                        else
                        {
                            JoinNodeLinux();
                        }
                    }
                }
            }
        });
    }