public void Connect() { if (!IsConnect()) { socket.Connect(IP, Port); } }
public void CreateInit(string strIP, int nPort, System.Object objExtend = null) { _strIP = strIP; _nPort = nPort; _listener = new KKBaseListener(msgQueue, MsgFactory.Room); _protocal = new KKBaseProtocal(); _socket = new USocket(_listener, _protocal); _socket.Connect(_strIP, nPort); }
public void Connect(string ip, int port) { IPAddress address; if (!IPAddress.TryParse(ip, out address)) { Log.Error("ip address is invalid!"); return; } socket.Connect(ip, port, address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6); netState = NetState.Connecting; }
public virtual void SendMessage(int nPort, CMD_Base_Req req) { USocket socket = _socketPool.NewSocket(_listener, _protocal); socket.Connect(_strIP, nPort, (success) => { if (!success) { return; } socket.Send(req.Serialize()); }); }
private void OnButtonClick(GameObject go) { //在这里监听按钮的点击事件 Debug.LogWarning(go.name); switch (go.name) { case "open": if (socket != null) { if (socket.getStatus() != USocket.STATUS_CLOSED) { socket.Close(); socket = null; } } SocketListner listner = new MyListner(); Protocal p = new LVProtocal(); socket = new USocket(listner, p); socket.Connect(ip, port); break; case "send": if (socket != null && socket.getStatus() == USocket.STATUS_CONNECTED) { AuthRequest auth = new AuthRequest(); auth.ucenterId = 99; auth.userCode = "zs"; // auth.loginid = "vH0cVEb2R2nRZOa4nxQz0ZsnTGC5pvf4Fn_sOxhLCQYsjGFRIEA5Pe1eTOwtPjrS"; auth.serverid = 1; // auth.testing = true; this.Send(auth); } break; case "close": if (socket != null) { if (socket.getStatus() != USocket.STATUS_CLOSED) { socket.Close(); socket = null; } break; } } }