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); }); }); } }
/// <summary> /// 选择服务器登陆方式 /// </summary> /// <param name="host">Host.</param> /// <param name="ip">Ip.</param> public void SelectServer(string host, int port) { _connection = createConnect(); _ip = host; _port = port; _connection.InitClient(_ip, _port, msgObj => { _connection.connect(null, (data) => { _connectSuccess = true; _canLogin = true; }); }); }
private void Start() { _connection = createConnect(); _connection.InitClient(_ip, _port, msgObj => { _connection.connect(null, data => { //process handshake call back data JsonObject msg = new JsonObject(); sendMsg(LobbyProtocol.P_LOBBY_REQ_CONNECT, msg, onRespConnet); }); }); }
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); }); }); }
//Login the chat application and new PomeloClient. public void Connect() { if (pomeloClient.netWorkState != enNetWorkState.Disconnected) { return; } int port = 3014; pomeloClient.InitClient(IPInput.text, port, msgObj => { //The user data is the handshake user params MessageObject user = new MessageObject(); pomeloClient.Connect(user, data => { //process handshake call back data MessageObject msg = new MessageObject(); msg["uid"] = NameInput.text; msg["pwd"] = PasswordInput.text; pomeloClient.Request("gate.gateHandler.login", msg, _onResponseRet); }); }); }