Esempio n. 1
0
        public void Connect(NetPoint point)
        {
            _point = point;

            _dataBuffer = new NetBuffer();
            //_recvThread = new Thread(new ThreadStart(DoRecv));
            _conThread = new Thread(new ThreadStart(DoConnect));
            _conThread.Start();
        }
Esempio n. 2
0
        public override void Connect(string host, int port, int timeout, Action <bool, string> onConnect, Action <int, byte[]> onReceive, Action onFailed)
        {
            netPoint = new NetPoint()
            {
                host = host, port = port
            };
            this.timeout = timeout;

            socket             = new NetSocket();
            socket.onConnect   = OnNetConnect;
            socket.onRecv      = OnRecvCmd;
            socket.onReconnect = OnReconnect;
            socket.Connect(netPoint);

            Invoke("CheckConnectTimeOut", timeout);
        }
Esempio n. 3
0
        public override void Connect(string host, int port, int timeout, Action <bool, string> onConnect, Action <int, byte[]> onReceive, Action onFailed)
        {
            netPoint = new NetPoint()
            {
                host = host, port = port
            };
            this.timeout = timeout;

            this.onConnect = onConnect;
            this.onReceive = onReceive;
            this.onFailed  = onFailed;

            // string _uri = string.Format("ws://{0}:{1}/", host, port);
            var url = string.Format("{0}:{1}/", host, port);

            _socket             = new WebSocket(new Uri(url));
            _socket.m_onConnect = () =>
            {
                CancelInvoke("CheckConnectTimeOut");
                onConnect(true, "");
            };
            _socket.m_onReconnect = () =>
            {
                if (IsConnect())
                {
                    onConnect(true, "");
                }
                else
                {
                    onFailed();
                }
            };

            StartCoroutine(_doConnect());

            Invoke("CheckConnectTimeOut", timeout);
        }