コード例 #1
0
 public void disconnectServer()
 {
     if (pclient != null)
     {
         isShowReConnectPanel = false;
         pclient.disconnect();
         pclient = null;
     }
 }
コード例 #2
0
 //When quit, release resource
 void Update()
 {
     if (Input.GetKey(KeyCode.Escape))
     {
         if (pc != null)
         {
             pc.disconnect();
         }
         Application.Quit();
     }
 }
コード例 #3
0
 //When quit, release resource
 void Update()
 {
     if (Input.GetKey(KeyCode.Escape) || Input.GetKey("escape"))
     {
         if (pclient != null)
         {
             pclient.disconnect();
         }
         Application.Quit();
     }
 }
コード例 #4
0
 //When quit, release resource
 void Update()
 {
     if (Input.GetKey(KeyCode.Escape))
     {
         if (pc != null)
         {
             pc.disconnect();
         }
         Application.Quit();
     }
     if (toNextScene)
     {
         Application.LoadLevel(Application.loadedLevel + 1);
     }
 }
コード例 #5
0
ファイル: LoginGUI.cs プロジェクト: NetEase/pomelo-unitychat
 //Login the chat application and new PomeloClient.
 void Login()
 {
     string url = "http://114.113.202.141:3088";
     pclient = new PomeloClient(url);
     pclient.init();
     JsonObject userMessage = new JsonObject();
     userMessage.Add("uid", userName);
     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://" + "114.113.202.141" + ":" + port.ToString());
                     pclient.init();
                     Entry();
                 }
             }
         }
     });
 }
コード例 #6
0
    //When quit, release resource
    void Update()
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            if (pomeloClient != null)
            {
                pomeloClient.disconnect();
            }
            Application.Quit();
        }

        if (_bNeedLoadScene)
        {
            Application.LoadLevel(SceneManager.GetActiveScene().buildIndex + 1);
        }
    }
コード例 #7
0
ファイル: NetWorkMgr.cs プロジェクト: swiftliang/NewGame
        private IEnumerator _doGetGsInfo(Action <Constants> cb)
        {
            _GateClientConnection.disconnect();

            _gameSvrIP   = null;
            _gameSvrPort = -1;

            Constants code = Constants.INVALID;

            _GateClientConnection.initClient(_loginInfo.gateHost, _loginInfo.gatePort, () =>
            {
                _GateClientConnection.connect(null, (data) =>
                {
                    Debug.Log("connect gate data: " + data);
                    SimpleJson.JsonObject msg = new SimpleJson.JsonObject();
                    msg["uid"] = _loginInfo.uid;
                    //msg["token"] = _loginInfo.token;
                    _GateClientConnection.request(RequestMsg.REQUEST_CONNECTOR, msg, (result) =>
                    {
                        code         = (Constants)Convert.ToInt32(result.data["code"]);
                        _gameSvrIP   = (string)result.data["host"];
                        _gameSvrPort = Convert.ToInt32(result.data["port"]);
                    });
                });
            });

            yield return(new WaitUntil(() => code != Constants.INVALID));

            if (cb != null)
            {
                cb(code);
            }
        }
コード例 #8
0
    void Awake()
    {
        callbacks = new Dictionary <string, CbFunc>();
        //初始化 PomeloClient
        client = new PomeloClient();
        client.initClient(host, port, () => {
            client.connect(null, (data) => {
                Debug.Log("connect back data" + data.ToString());
                JsonObject js = new JsonObject();
                js["uid"]     = 12234;
                client.request(router, js, (connectData) =>
                {
                    string conHost = connectData["host"].ToString();
                    int conPort    = int.Parse(connectData["port"].ToString());
                    Debug.Log(conHost + "#" + conPort.ToString());
                    client.disconnect();

                    client = new PomeloClient();
                    client.initClient(conHost, conPort, () =>
                    {
                        client.connect(null, (cb) => {
                        });
                    });
                });
            });
        });
    }
コード例 #9
0
ファイル: MainWindow.xaml.cs プロジェクト: soulkey99/byserver
 void OnQuery2(object sender, RoutedEventArgs e)
 {
     pc2 = new PomeloClient(this.ipAddr2.Text, 3014);
     pc2.connect(null, delegate(JsonObject data) {
         JsonObject msg = new JsonObject();
         msg["userID"]  = "demo2";
         pc2.request("gate.gateHandler.queryEntry", msg, delegate(JsonObject result) {
             if (Convert.ToInt32(result["statusCode"]) == 900)
             {
                 string host = (string)result["host"];
                 int port    = Convert.ToInt32(result["port"]);
                 pc2.disconnect();
                 pc2.Dispose();
                 pc2   = null;
                 host2 = host;
                 port2 = port;
                 this.Dispatcher.BeginInvoke((Action)(() =>
                 {
                     this.Status21.Text = "success, " + host + ":" + port.ToString();
                 }));
                 Log2("query success, " + host + ":" + port.ToString());
             }
             else
             {
                 this.Dispatcher.BeginInvoke((Action)(() =>
                 {
                     this.Status21.Text = "error, " + result["message"];
                 }));
                 Log2("error, " + result["message"]);
             }
         });
     });
 }
コード例 #10
0
ファイル: LoginGUI.cs プロジェクト: sfszh/pomelo-unitychat
    //Login the chat application and new PomeloClient.
    void Login()
    {
        string url = "http://114.113.202.141:3088";

        pclient = new PomeloClient(url);
        pclient.init();
        JsonObject userMessage = new JsonObject();

        userMessage.Add("uid", userName);
        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://" + "114.113.202.141" + ":" + port.ToString());
                        pclient.init();
                        Entry();
                    }
                }
            }
        });
    }
コード例 #11
0
        public static void OnQuery(JsonObject result)
        {
            if (Convert.ToInt32(result["code"]) == 200)
            {
                pc.disconnect();

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

                pc.NetWorkStateChangedEvent += (state) =>
                {
                    Console.WriteLine(state);
                };

                pc.initClient(host, port, () =>
                {
                    pc.connect(null, (data) =>
                    {
                        JsonObject userMessage = new JsonObject();
                        Console.WriteLine("on connect to connector!");

                        //Login
                        JsonObject msg  = new JsonObject();
                        msg["username"] = "******";
                        msg["rid"]      = "pomelo";

                        pc.request("connector.entryHandler.enter", msg, OnEnter);
                    });
                });
            }
        }
コード例 #12
0
 public void Disconnect()
 {
     if (pclient != null)
     {
         pclient.disconnect();
     }
     pclient = null;
 }
コード例 #13
0
 public void Uninitialize()
 {
     _isWorking = false;
     if (_workThread != null)
     {
         _workThread.Abort();
         _workThread = null;
     }
     if (_pomeloClient != null)
     {
         _pomeloClient.disconnect();
         _pomeloClient.Dispose();
         _pomeloClient = null;
     }
     //销毁Net缓存器
     NetVendor.DestroyInstance();
 }
コード例 #14
0
ファイル: NetworkClient.cs プロジェクト: zj831007/knight
 public void Disconnect()
 {
     if (mClient != null)
     {
         mClient.disconnect();
         mClient = null;
         Debug.Log("Disconnected!");
     }
 }
コード例 #15
0
 /// <summary>
 /// disconnect the client
 /// </summary>
 public void Disconnect()
 {
     if (m_Conn != null)
     {
         m_Conn.disconnect();
         m_Conn = null;
     }
     NetState = null;
 }
コード例 #16
0
 public static void onQuery(JsonObject result)
 {
     if (Convert.ToInt32(result["code"]) == 200)
     {
         string host = (string)result["host"];
         int    port = Convert.ToInt32(result["port"]);
         pc.disconnect();
         startConnect(host, port);
     }
 }
コード例 #17
0
    //When quit, release resource
    void Update()
    {
        text_hello.text = "Hello:" + userName;

        if (Input.GetKey(KeyCode.Escape) || Input.GetKey("escape"))
        {
            if (pclient != null)
            {
                pclient.disconnect();
            }
            Application.Quit();
        }
        if (_bNeedLoadScene)    // 选好房间后直接跳转
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 2);
        }
        else
        {
            // msglist
            foreach (Transform child in Scroll_View_roomList.transform.FindChild("Viewport").FindChild("Content").transform)
            {
                Destroy(child.gameObject);
            }

            if (roomList != null && roomList.Count >= 1)
            {
                foreach (string roomid in roomList)
                {
                    GameObject t3 = new GameObject();
                    t3.transform.localPosition = new Vector3(0, 0, 0);
                    t3.AddComponent <Text>();
                    t3.GetComponent <Text>().text      = showstr(roomid, hashMap[roomid]);
                    t3.GetComponent <Text>().alignment = TextAnchor.MiddleCenter;
                    t3.GetComponent <Text>().fontSize  = 20;
                    t3.GetComponent <Text>().font      = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
                    RectTransform rectTransform2 = t3.GetComponent <RectTransform>();
                    rectTransform2.localPosition = new Vector3(0, 0, 0);
                    t3.transform.parent          = Scroll_View_roomList.transform.FindChild("Viewport").FindChild("Content");
                }
            }
        }
    }
コード例 #18
0
 void LoginGateServerCallback(JsonObject result)
 {
     if (Convert.ToInt32(result["code"]) == 200)
     {
         _pomelo.disconnect();
         LoginConnectorServer(result);
     }
     else
     {
         AppendLog("oh shit... 请求 connector 出错");
     }
 }
コード例 #19
0
ファイル: NetMgr.cs プロジェクト: isoundy000/shmj3d
    void OnQuery(JsonObject ret)
    {
        Debug.Log("OnQuery disconnect");
        pc.disconnect();

        if (!ret.ContainsKey("code") || !ret.ContainsKey("host") || !ret.ContainsKey("port"))
        {
            Debug.Log("OnQuery key not found!");
            return;
        }

        int code = Convert.ToInt32(ret ["code"]);

        if (code != 0)
        {
            return;
        }

        string host = (string)ret["host"];
        int    port = Convert.ToInt32(ret["port"]);

        Entry(host, port);
    }
コード例 #20
0
 public static void Init(string host, int port, int uid, Action <JsonObject> act)
 {
     cli = new PomeloClient();
     cli.initClient(host, port, () => {
         cli.connect((hs) => {
             JsonObject msg = new JsonObject();
             msg ["uid"]    = uid;
             cli.request("gate.gateHandler.queryEntry", msg, data => {
                 cli.disconnect();
                 Entry(Convert.ToString(data ["host"]), Convert.ToInt32(data ["port"]), uid, act, data);
             });
         });
     });
 }
コード例 #21
0
    public void Connect(string host, int port, LuaInterface.LuaFunction func)
    {
        pc = new PomeloClient();
        pc.initClient(host, port);
        pc.connect(null, (data) => {
            JsonObject msg  = new JsonObject();
            msg["deviceId"] = deviceId;
            msg["id"]       = 1;
            pc.request("gate.gateHandler.queryEntry", msg, (result) => {
                Debug.Log("--------------------------------------");
                Debug.Log(result.ToString());
                Debug.Log("--------------------------------------");
                if (Convert.ToInt32(result["code"]) == 200)
                {
                    pc.disconnect();

                    string h = (string)result["host"];
                    int p    = Convert.ToInt32(result["port"]);
                    pc       = new PomeloClient();
                    pc.initClient(h, p);
                    pc.connect(null, (dd) =>
                    {
                        JsonObject conectorMessage = new JsonObject();
                        conectorMessage.Add("deviceId", deviceId);
                        pc.request("connector.entryHandler.entry", conectorMessage, (ret) =>
                        {
                            Debug.Log("--------------------------------------");
                            Debug.Log(ret.ToString());
                            Debug.Log("--------------------------------------");
                            if (Convert.ToInt32(ret["code"]) == 200)
                            {
                                isConnected = true;
                                EventsListen();
                            }

                            if (func != null)
                            {
                                PomeloPackage pkg = new PomeloPackage();
                                pkg.luaFunc       = func;
                                pkg.ReturnData    = ret.ToString();
                                Debug.Log("!!!!!!!!!!!!!!!!!!!! " + pkg.ReturnData);
                                AddResultPackage(pkg);
                            }
                        });
                    });
                }
            });
        });
    }
コード例 #22
0
ファイル: NetWorkMgr.cs プロジェクト: swiftliang/NewGame
 public void LoginGameServer(Action <GameInfo> cb)
 {
     _GameSvrConnection.disconnect();
     _GameSvrConnection.initClient(_gameSvrIP, _gameSvrPort, () =>
     {
         _GameSvrConnection.connect(null, data =>
         {
             Debug.Log("connect connector data: " + data.ToString());
             JsonObject msg = new JsonObject();
             msg["uid"]     = _loginInfo.uid;
             msg["token"]   = _loginInfo.token;
             msg["game"]    = "MDGame";
             _GameSvrConnection.request(RequestMsg.REQUEST_ENTER, msg, result =>
             {
                 if (cb != null)
                 {
                     Message retMsg = (Message)result;
                     GameInfo ginfo = JsonReader.Deserialize <GameInfo>(retMsg.rawString);
                     cb(ginfo);
                 }
             });
         });
     });
 }
コード例 #23
0
 public static void getGameServerHandler(Action <PomeloClient> action)
 {
     getGameServerList((list) => {
         Debug.Log("========>>server list:\t" + list);
         if (Convert.ToInt32(list["code"]) == 200)
         {
             _gameClient.disconnect();
             _gameClient = new PomeloClient((string)list["host"], Convert.ToInt32(list["port"]));
             _gameClient.connect(null, (client) => {
                 action(_gameClient);
             });
         }
         else
         {
             Debug.Log("Get Game Server List Error...");
             action(null);
         }
     });
 }
コード例 #24
0
        public static void OnQuery(JsonObject result)
        {
            if (Convert.ToInt32(result["code"]) == 200)
            {
                pc.disconnect();

                string host = (string)result["host"];
                int    port = Convert.ToInt32(result["port"]);
                pc = new PomeloClient(host, port);
                pc.connect(null, (data) => {
                    JsonObject userMessage = new JsonObject();
                    Console.WriteLine("on connect to connector!");
                    pc.on(PomeloClient.EVENT_DISCONNECT, onDisconnect);

                    //Login
                    JsonObject msg  = new JsonObject();
                    msg["username"] = "******";
                    msg["rid"]      = "pomelo";

                    pc.request("connector.entryHandler.entry", msg, OnEnter);
                });
            }
        }
コード例 #25
0
 void OnDestroy()
 {
     client.disconnect();
 }
コード例 #26
0
 //切断连接
 public void disconnect()
 {
     pclient.disconnect();
 }
コード例 #27
0
    //When quit, release resource
    void Update()
    {
        if (Input.GetKey(KeyCode.Escape) || Input.GetKey("escape"))
        {
            if (pclient != null)
            {
                pclient.disconnect();
            }
            Application.Quit();
        }

        foreach (Transform child in scroll.transform.FindChild("Viewport").FindChild("Content").transform)
        {
            Destroy(child.gameObject);
        }

        if (userList != null && userList.Count >= 1)
        {
            foreach (string roomid in userList)
            {
                GameObject t3 = new GameObject();
                t3.transform.localPosition = new Vector3(0, 0, 0);
                t3.AddComponent <Text>();
                t3.GetComponent <Text>().text      = roomid;
                t3.GetComponent <Text>().color     = Color.white;
                t3.GetComponent <Text>().fontSize  = 20;
                t3.GetComponent <Text>().alignment = TextAnchor.MiddleCenter;
                t3.GetComponent <Text>().font      = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
                RectTransform rectTransform2 = t3.GetComponent <RectTransform>();
                rectTransform2.localPosition = new Vector3(0, 0, 0);
                t3.transform.parent          = scroll.transform.FindChild("Viewport").FindChild("Content");
            }
        }

        // 房间人数
        int userlistLen = userList.Count;

        roomNum.text = userlistLen.ToString();

        // msglist
        foreach (Transform child in scroll_msg.transform.FindChild("Viewport").FindChild("Content").transform)
        {
            Destroy(child.gameObject);
        }

        GameObject msgPrefab = Resources.Load <GameObject>("Prefabs/ChatMsg2");

        foreach (ChatRecord cr in chatRecords)
        {
            GameObject t2 = (GameObject)Instantiate(msgPrefab);
            t2.transform.FindChild("msg").gameObject.GetComponent <Text>().text = cr.name + ": " + cr.dialog;
            RectTransform rectTransform2 = t2.GetComponent <RectTransform>();
            //rectTransform2.localPosition = new Vector3(0, 0, 0);
            t2.transform.parent = scroll_msg.transform.FindChild("Viewport").FindChild("Content");
        }

        /*
         * foreach (ChatRecord cr in chatRecords)
         * {
         *  string s = cr.name + ": " + cr.dialog;
         *  GameObject t2 = new GameObject();
         *  t2.AddComponent<Text>();
         *  t2.GetComponent<Text>().text = s;
         *  t2.GetComponent<Text>().font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
         *  RectTransform rectTransform2 = t2.GetComponent<RectTransform>();
         *  rectTransform2.localPosition = new Vector3(0, 0, 0);
         *  t2.transform.parent = scroll_msg.transform.FindChild("Viewport").FindChild("Content");
         * }
         */
    }
コード例 #28
0
        private void button2_Click(object sender, EventArgs e)
        {
            this.label3.Text = "断开连接";

            _pomeloClient.disconnect();
        }
コード例 #29
0
ファイル: Network.cs プロジェクト: yuchenwuhen/skillEditor
 public void DisConnect()
 {
     isByClientCall = true;
     client.disconnect();
 }
コード例 #30
0
    //When quit, release resource
    void Update()
    {
        if (Input.GetKey(KeyCode.Escape) || Input.GetKey("escape"))
        {
            if (pclient != null)
            {
                pclient.disconnect();
            }
            Application.Quit();
        }

        //
        foreach (GameObject go in userGameObject)
        {
            Destroy(go);
        }
        userGameObject.Clear();

        if (userName != null && userName != "")
        {
            foreach (Player p in userlist)
            {
                Vector3    v3 = new Vector3(p.posx, p.posy, 0);
                GameObject mon;
                mon = (GameObject)Instantiate(Resources.Load("ME"), v3, Quaternion.identity);
                mon.GetComponent <TextMesh>().text = p.name;
                if (p.name == userName)
                {
                    mon.GetComponent <TextMesh>().color = Color.red;
                }
                else
                {
                    mon.GetComponent <TextMesh>().color = Color.blue;
                }
                mon.transform.position = v3;

                userGameObject.Add(mon);
            }
        }

        // 遍历动作
        foreach (MoveRecord mr in moveRecords)
        {
            Debug.Log("make a move");

            foreach (GameObject go2 in userGameObject)
            {
                if (go2.GetComponent <TextMesh>().text == mr.name)
                {
                    float   walkSpeed = 2f;
                    Vector3 v3        = new Vector3(mr.new_posx, mr.new_posy, 0);
                    Vector3 offSet    = v3 - go2.transform.position;

                    //if(Vector3.Distance(v3, go2.transform.position) > 0.02f)
                    //    go2.transform.position += walkSpeed * offSet.normalized * Time.deltaTime;
                    go2.transform.position = v3;

                    //int len = userlist.Count;
                    //for (int i = 0; i < len; i++)
                    //{
                    //    if (((Player)userlist[i]).name == mr.name) {
                    //        ((Player)userlist[i]).posx = mr.new_posx;
                    //        ((Player)userlist[i]).posx = mr.new_posy;
                    //    }
                    //}
                }
            }
            // 更新userList集合
            foreach (Player p in userlist)
            {
                if (p.name == mr.name)
                {
                    p.posx = mr.new_posx;
                    p.posy = mr.new_posy;
                }
            }
        }
        moveRecords.Clear();

        // 按A键
        if (Input.GetKeyDown(KeyCode.A))
        {
            Vector3 pos = Input.mousePosition;

            foreach (GameObject go2 in userGameObject)
            {
                if (go2.GetComponent <TextMesh>().text == userName)
                {
                    //float walkSpeed = 2f;
                    // float deltaX = pos.x - go2.transform.position.x;
                    // float deltaY = pos.y - go2.transform.position.y;
                    //Vector3 v3 = new Vector3(go2.transform.position.x - 1, go2.transform.position.y, 0);
                    //go2.transform.position = transform.position + walkSpeed * v3 * Time.deltaTime;

                    JsonObject message = new JsonObject();
                    message.Add("rid", LoginGUI.channel);
                    message.Add("posx", (int)go2.transform.position.x - 1);
                    message.Add("posy", (int)go2.transform.position.y);
                    message.Add("from", LoginGUI.userName);
                    message.Add("target", "*");
                    pclient.request("chat.chatHandler.move", message, (data) =>
                    {
                        Debug.Log(data.ToString());
                        // moveRecords.Add(new MoveRecord(userName, (int)go2.transform.position.x - 1, (int)go2.transform.position.y));
                    });
                }
            }
        }

        // D键
        if (Input.GetKeyDown(KeyCode.D))
        {
            Vector3 pos = Input.mousePosition;

            foreach (GameObject go2 in userGameObject)
            {
                if (go2.GetComponent <TextMesh>().text == userName)
                {
                    float walkSpeed = 2f;
                    // float deltaX = pos.x - go2.transform.position.x;
                    // float deltaY = pos.y - go2.transform.position.y;
                    Vector3 v3 = new Vector3(go2.transform.position.x + 1, go2.transform.position.y, 0);
                    go2.transform.position = transform.position + walkSpeed * v3 * Time.deltaTime;
                }
            }

            foreach (Player p in userlist)
            {
                if (p.name == userName)
                {
                    p.posx = p.posx + 1;
                }
            }
        }
    }
コード例 #31
0
 private void Disconnect()
 {
     client.disconnect();
     Debug.Log("Disconnected!");
 }