示例#1
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;
            }
        }
    }
示例#2
0
 public bool IsConnect()
 {
     return(socket.getStatus() == USocket.STATUS_CONNECTED);
 }