/// <summary> /// 与服务器器建立连接 /// </summary> /// <param name="conResult">Con result.</param> public void Connect(Action <bool> conResult) { connectResultCallback = conResult; if (pclient != null && conResult != null) { Debug.Log("(pclient != null && conResult != null)"); InvokeConnectResult(true); return; } ChangeConnectStatus(ConnectStatus.CONNECTING); EventDispatcher.Instance().RegistEventListener(NetDataRequestTip.NET_REQUEST_START, NetDataRequestTip.startReq); EventDispatcher.Instance().RegistEventListener(NetDataRequestTip.NET_REQUEST_END, NetDataRequestTip.endReq); EventDispatcher.Instance().RegistEventListener(NetDataRequestTip.NET_CONNECT_CLOSE, NetDataRequestTip.ConnectClose); EventDispatcher.Instance().DispatchEvent(NetDataRequestTip.NET_REQUEST_START, null); pclient = new PomeloClient(); pclient.NetWorkStateChangedEvent += OnGateServerNetWorkStateChange; try{ pclient.initClient(CGNetConst.HOST, CGNetConst.POST, () => { pclient.connect(null, conData1 => { Debug.Log("Gate服务器连接成功!"); pclient.request(CGNetConst.ROUTE_LOGIN, delegate(JsonObject jsonObject) { Debug.Log("PARA_CODE = " + jsonObject [CGNetConst.PARA_CODE]); if (Convert.ToInt32(jsonObject [CGNetConst.PARA_CODE]) == CGNetConst.RESULT_CODE_SUC) { Disconnect(true); Debug.Log("与Gate服务器断开连接,准备连接游戏服务器……"); Debug.Log("host=" + (string)jsonObject [CGNetConst.PARA_HOST] + " port=" + jsonObject [CGNetConst.PARA_PORT]); pclient = new PomeloClient(); pclient.NetWorkStateChangedEvent += OnNetWorkStateChange; pclient.initClient((string)jsonObject [CGNetConst.PARA_HOST], Convert.ToInt32(jsonObject [CGNetConst.PARA_PORT]), () => { pclient.connect(null, conData2 => { ChangeConnectStatus(ConnectStatus.CONNECTED); Debug.Log("游戏服务器连接成功!"); // if(conResult != null) // { // conResult(true); // } }); }); } else { Debug.Log("Connect faild!"); InvokeConnectResult(false); // if(conResult != null) // { // conResult(false); // } } }); }); }); }catch (Exception e) { Debug.Log(e.ToString()); } }
public static void Main() { JsonObject server = read("./server.json"); string host = (string)server["host"]; int port = Convert.ToInt32(server["port"]); Console.WriteLine("before init"); pc = new PomeloClient(host, port); Console.WriteLine("before connect"); pc.connect(null, delegate(JsonObject data){ Console.WriteLine("after connect " + data.ToString()); JsonObject msg = new JsonObject(); msg["uid"] = 1; pc.request("gate.gateHandler.queryEntry", msg, onQuery); }); while (true) { string str = Console.ReadLine(); if (str != null) { send(str); } System.Threading.Thread.Sleep(100); } }
// public static public Network() { client = new PomeloClient(); requests = new Queue <RequestMessage>(); client.NetWorkStateChangedEvent += NetWorkStateChange; netWorkState = NetWorkState.CLOSED; }
//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(); } } } }); }
public void prev(int step = 1) { int id = current / 3; if (id >= step) { id -= step; } else { id = 0; } NetMgr net = NetMgr.GetInstance(); PomeloClient pc = net.pc; pc.flush(); RoomMgr rm = RoomMgr.GetInstance(); rm.prepareReplay(mRoom, mBaseInfo); mCount = mBaseInfo.mahjongs.Count; gotoAction(id); }
/// <summary> /// connect to server and response /// </summary> /// <param name="ip"></param> /// <param name="port"></param> /// <param name="user">handshake msg for connect</param> /// <param name="action">default request callback</param> public void Connect(string ip, int port, JsonObject user, Action <JsonObject> action) { if (m_Conn != null) { Debug.Log("the network has been connected!"); return; } Debug.Log("connect to ip: " + ip + " port: " + port); m_Conn = new PomeloClient(); m_Conn.NetWorkStateChangedEvent += (state) => { Debug.Log("network state: " + state); if (NetState != null) { NetState.Invoke(state); } }; m_Conn.initClient(ip, port, () => { m_Conn.connect(user, (rt) => { Dispatcher.Current.BeginInvoke(() => { action.Invoke(rt); }); }); }); }
void OnQuery(JsonObject result) { Debug.Log("OnQuery called. Acquired data from gate server."); if (Convert.ToInt32(result["code"]) == 200) { pc.disconnect(); string host = (string)result["host"]; int port = Convert.ToInt32(result["port"]); Debug.Log("Connecting to connector server: " + host + ":" + port); pc = new PomeloClient(); pc.initClient(host, port, () => { pc.connect((data) => { Entry(); }); }); } else { Debug.Log("Connection error."); } }
private void Connect() { client = new PomeloClient(); client.initClient(url, port, () => { Debug.Log("Pomelo client init success!"); }); JsonNode user = new JsonClass(); user.Add("user", new JsonData("Winddy")); user.Add("pwd", new JsonData("123")); bool result = client.connect(user, new System.Action <JsonNode>(OnConnection)); if (result) { Debug.Log("Connect success!"); } else { Debug.Log("Connect failed!"); } //ClientTest.loginTest("127.0.0.1", 3014); }
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.initClient(host, port); pc.connect(null, (data) => { JsonObject conectorMessage = new JsonObject(); conectorMessage.Add("deviceId", deviceId); pc.request("connector.entryHandler.entry", conectorMessage, (ret) => { if (Convert.ToInt32(ret["code"]) == 200) { isConnected = true; EventsListen(); Debug.Log("...... " + data); } }); }); } }
public static void resetClient(PomeloClient pc) { gate.gateHandler.pc = pc; connector.entryHandler.pc = pc; chat.chatHandler.pc = pc; ServerEvent.pc = pc; }
public static void LReconnect(string url, int port, int playerid, string route) { PomeloSocketEntry.Client = new PomeloClient(); PomeloSocketEntry.Client.NetWorkStateChangedEvent += (NWorkStateChangedEvent)(state => { PomeloSocketEntry.networkState = state; Debug.Log(PomeloSocketEntry.networkState); if (PomeloSocketEntry.NwStateChangeDel == null) { return; } PomeloSocketEntry.NwStateChangeDel((int)PomeloSocketEntry.networkState); }); PomeloSocketEntry.Client.initClient(url, port, (Action)(() => { JsonObject user = new JsonObject(); PomeloSocketEntry.Client.connect(user, (Action <JsonObject>)(responseData => { Debug.Log(responseData + "handshake call back data"); if (NetWorkState.CONNECTED != PomeloSocketEntry.networkState) { return; } PomeloSocketEntry.LSocketRequest(new JsonObject() { { "playerId", (object)playerid } }, route); })); })); }
private void onRespConnet(Message msg) { JsonObject result = msg.jsonObj; System.Object code = null; if (result.TryGetValue("code", out code)) { if (Convert.ToInt32(code) == 500) { return; } else { _connection.Disconnect(PackageType.PKG_NONE); _connection = null; if (_isSelectServerMode) { _serverList = msg; _connectSuccess = true; _canLogin = false; } else { System.Object host, port; if (result.TryGetValue("host", out host) && result.TryGetValue("port", out port)) { SelectServer(host.ToString(), Convert.ToInt32(port)); } } } } }
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); }); }); } }
void OnQuery(JsonObject result) { if (Convert.ToInt32(result["code"]) == 200) { pomeloClient.disconnect(); string connectorHost = (string)result["host"]; int connectorPort = Convert.ToInt32(result["port"]); pomeloClient = new PomeloClient(); pomeloClient.initClient(connectorHost, connectorPort, () => { //The user data is the handshake user params JsonObject user = new JsonObject(); pomeloClient.connect(user, data => { Entry(); }); }); // 请求到了connector数据后,跳转场景 //_bNeedLoadScene = true; } }
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) => { }); }); }); }); }); }
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); }); }); } }
private PomeloClient createConnect() { PomeloClient connection = new PomeloClient(); connection.on("onTick", msg => { Debug.unityLogger.Log("onTick:" + msg.rawString); }); //listen on network state changed event connection.on(PomeloClient.DisconnectEvent, msg => { //网络错误,诸如已经掉线等等 Debug.unityLogger.Log("Network error, reason: " + msg.jsonObj["reason"]); if (_disconnectCallback != null) { _disconnectCallback(msg); } }); connection.on(PomeloClient.ErrorEvent, msg => { //没网 Debug.unityLogger.Log("Error, reason: " + msg.jsonObj ["reason"]); if (_errorCallback != null) { _errorCallback(msg); } }); return(connection); }
//Login the chat application and new PomeloClient. void Login() { //string host = "120.27.163.31"; string host = "127.0.0.1"; int port = 3014; pomeloClient = new PomeloClient(); //listen on network state changed event pomeloClient.NetWorkStateChangedEvent += (state) => { Debug.logger.Log("CurrentState is:" + state); }; pomeloClient.initClient(host, port, () => { //The user data is the handshake user params JsonObject user = new JsonObject(); //user["uid"] = userName; pomeloClient.connect(user, data => { //process handshake call back data JsonObject msg = new JsonObject(); msg["uid"] = userName; pomeloClient.request("gate.gateHandler.queryEntry", msg, OnQuery); }); }); }
//Login the chat application and new PomeloClient. void Login() { string host = "127.0.0.1"; int port = 33014; pc = new PomeloClient(); pc.NetWorkStateChangedEvent += (state) => { Debug.Log("NetWorkStateChangedEvent: " + state); }; Debug.Log("Connecting to gate server: " + host + ":" + port); pc.initClient(host, port, () => { Debug.Log("pc.initClient callback."); pc.connect((data) => { Debug.Log("pc.connect callback."); JsonObject msg = new JsonObject(); msg["uid"] = userName; pc.request("gate.gateHandler.queryEntry", msg, OnQuery); //pc.request("gate.gateHandler.queryEntry", msg, (response) => { // Debug.Log("callback here!"); //}); }); }); }
void Start() { const string logFile= "/tmp/cspomelo.log"; if(InitLog(logFile) != 0) { DLog("error open log file : " + logFile); } PomeloClient.Log = DLog; PomeloClient.LibInit(PomeloClient.PC_LOG_DEBUG, null, null); client = new PomeloClient(); if(! client.Init(false, false)) { DLog("client init has occur a fatal error"); return; } DLog("client inited"); client.OnConnectSuccess += OnConnect; client.OnConnectSuccess += ()=>{ DLog("client connected"); }; client.OnConnectFail += (msg)=>{ DLog("client connect fail : " + msg); }; client.OnDisconnect += OnDisconnect; client.OnDisconnect += (msg)=>{ DLog("client disconnected : " + msg); }; client.OnError += (err)=>{ DLog("client occur an error : " + err); }; client.Connect(ServerHost(), ServerPort()); }
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"]); } }); }); }
//建立起一条新的连接 public void newSocket() { pclient = new PomeloClient(); pclient.NetWorkStateChangedEvent += (state) => { Debug.Log(state); //Console.WriteLine(state); }; pclient.initClient(host, port, () => { //The user data is the handshake user params JsonObject user = new JsonObject(); pclient.connect(user, data => { ConnectorSender.sendEnter(); //pclient.request(Routes.CONNECTOR_ENTER, new JsonObject(), OnEnterConnector); }); //把广播事件的名称都注册到pomelo中 foreach (KeyValuePair <string, Action <JsonObject> > pair in BroadcastFact.callbacks) { this.registBroadcast(pair.Key); } }); }
//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(); } } } }); }
//Login the chat application and new PomeloClient. void Login() { userName = infield_username.text; // 获取输入框中的信息 if (userName == "") { return; } string host = "127.0.0.1"; // gate的host和port int port = 3014; pomeloClient = new PomeloClient(); //listen on network state changed event pomeloClient.NetWorkStateChangedEvent += (state) => { Debug.logger.Log("CurrentState is:" + state); }; // 请求gate服务器,得到connector服务器的host和clientPort pomeloClient.initClient(host, port, () => { // user 消息传递给 gate.gateHandler.queryEntry JsonObject user = new JsonObject(); user["uid"] = userName; pomeloClient.connect(user, data => { //process handshake call back data JsonObject msg = new JsonObject(); msg["uid"] = userName; pomeloClient.request("gate.gateHandler.queryEntry", msg, OnQuery); }); }); }
public void Disconnect() { if (pclient != null) { pclient.disconnect(); } pclient = null; }
public void Disconnect() { if (mClient != null) { mClient.disconnect(); mClient = null; Debug.Log("Disconnected!"); } }
private void Connect() { itsClient = new PomeloClient(itsURL, itsPort); //The user data is the handshake user params //JsonObject user = new JsonObject(); //user.Add(new KeyValuePair<string,object>("user","flo")); itsClient.Connect(null, new System.Action <JSONNode>(OnConnection)); }
private void OnOnDisconnect() { pc = null; if (_port > 0) { IsReConnect = true; // ConnectGameServer(_port); } }
public void disconnectServer() { if (pclient != null) { isShowReConnectPanel = false; pclient.disconnect(); pclient = null; } }
/// <summary> /// disconnect the client /// </summary> public void Disconnect() { if (m_Conn != null) { m_Conn.disconnect(); m_Conn = null; } NetState = null; }
public Protocol(PomeloClient pc, System.Net.Sockets.Socket socket) { this.pomeloClient = pc; this.transporter = new Transporter(socket, this.processMessage); this.transporter.onDisconnect = OnDisconnect; this.handshake = new HandShakeService(this); this.state = enProtocolState.start; }
public void sync() { NetMgr net = NetMgr.GetInstance(); PomeloClient pc = net.pc; JsonObject data = new JsonObject(); pc.pseudo("game_sync_push", data); }
//Login the chat application and new PomeloClient. void Login() { string host = "127.0.0.1"; int port = 3014; pc = new PomeloClient(host, port); pc.connect(null, (data)=>{ JsonObject msg = new JsonObject(); msg["uid"] = userName; pc.request("gate.gateHandler.queryEntry", msg, OnQuery); }); }
public bool connectTo(string name,string host,int port,NetStateChanged stateCallBack) { PomeloClient pclient = new PomeloClient(); if (addClient (name, pclient)) { //listen on network state changed event pclient.NetWorkStateChangedEvent += (state) => { string clientName = namesByClient[pclient]; switch (state) { case NetWorkState.ERROR: { stateCallBack(clientName,SocketNetState.ERROR); }break; case NetWorkState.CLOSED: { stateCallBack(clientName,SocketNetState.CLOSED); }break; case NetWorkState.TIMEOUT: { stateCallBack(clientName,SocketNetState.TIMEOUT); }break; case NetWorkState.CONNECTED: { stateCallBack(clientName,SocketNetState.CONNECTED); }break; case NetWorkState.CONNECTING: { stateCallBack(clientName,SocketNetState.CONNECTING); }break; case NetWorkState.DISCONNECTED: { stateCallBack(clientName,SocketNetState.DISCONNECTED); }break; } }; pclient.initClient(host, port, () => { //The user data is the handshake user params JsonObject user = new JsonObject(); pclient.connect(user, data => { //process handshake call back data }); }); return true; } else { return false; } }
// 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."); }
/// <summary> /// cleanup the pomelo client /// NOTE it's not the best practice since it would not invoke on ios /// </summary> /// void OnApplicationQuit() { if(client != null) { DLog("client ready to destroy"); client.Destroy(); client = null; PomeloClient.LibCleanup(); DLog("destroy client successful"); } else { DLog("no client to destroy!"); } }
public static void loginTest(string host, int port) { pc = new PomeloClient(host, port); pc.connect(null, data=>{ Console.WriteLine("on data back" + data.ToString()); JsonObject msg = new JsonObject(); msg["uid"] = 111; pc.request("gate.gateHandler.queryEntry", msg, OnQuery); }); while(true){ System.Threading.Thread.Sleep(100); }; }
public static void OnQuery(JsonObject result) { if(Convert.ToInt32(result["code"]) == 200){ Console.WriteLine("dis connect"); 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!"); }); } }
public static void loginTest(string host, int port) { pc = new PomeloClient(); pc.NetWorkStateChangedEvent += (state) => { Console.WriteLine(state); }; pc.initClient(host, port, () => { pc.connect(null, data => { Console.WriteLine("on data back" + data.ToString()); JsonObject msg = new JsonObject(); msg["uid"] = 111; pc.request("gate.gateHandler.queryEntry", msg, OnQuery); }); }); }
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)=>{ 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.enter", msg, OnEnter); }); } }
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)=>{ Entry(); }); } }
// Use this for initialization void Start() { lsTablePlay = new Dictionary<string, TableController> (); lsTableWait = new Dictionary<string, TableController> (); pclient = GameManager._pclient; Util.loadPictureCB = LoadPictureCallback; //Create table if (GameManager.instance.roomData.Length > 0) { IList iLsTable = Util.DeserializeJsonArrayToList(GameManager.instance.roomData); foreach (var obj in iLsTable){ IDictionary dict = obj as IDictionary; //string id = System.Convert.ToString(dict["id"]); // _newData = dict["id"]; // _numTablePlay += 1; CreateNewTable(dict, true); } _numTablePlay += iLsTable.Count; } //Handle events pclient.on("onNewRoom", (data) => { Debug.Log (data["room"]); _newData = Util.DeserializeJsonToDict(System.Convert.ToString(data["room"])); _numTablePlay += 1; // Thay doi numTable de loop trong update chay }); pclient.on("onDeleteRoom", (data) => { Debug.Log (data); string tableID = System.Convert.ToString(data["room"]); _numTablePlay -= 1; lsDeletePlayID.Add(tableID); }); GameManager.instance._rc = this; StartCoroutine (ListenRoomAction ()); }
// Use this for initialization void Start() { manager = GameManager.instance; pclient = GameManager._pclient; StartCoroutine (ListenLoginAction()); }
IEnumerator WaitForLoginRequest(WWW www) { yield return www; // check for errors if (www.error == null) { Debug.Log("WWW Ok!: " + www.text); GameManager.instance.user.userID = www.text.Replace("\"", ""); pclient = GameManager._pclient; if (pclient != null){ pclient.connect(null, data => { Debug.Log ("Connect server ok ..."); JsonObject msg = new JsonObject(); pclient.request(Constants.GATESERVER, msg, OnResponseFromGate); }); } else{ Debug.LogError("Pomelo client null"); } } else { Debug.Log("WWW Error: "+ www.error); } }
private bool addClient(string name,PomeloClient client) { if (!clientsByName.ContainsKey (name) && !namesByClient.ContainsKey (client)) { clientsByName.Add (name, client); namesByClient.Add (client, name); return true; } else { return false; } }