Пример #1
0
 void OnClose()
 {
     netState = NetState.Closed;
     if (socket != null)
     {
         socket.Close();
     }
     Messenger.BroadcastAsync(MessageId.NetworkDisconnect);
 }
Пример #2
0
 public void Close()
 {
     if (socket.getStatus() != USocket.STATUS_CLOSED)
     {
         socket.Close();
     }
 }
Пример #3
0
    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;
            }
        }
    }