コード例 #1
0
ファイル: ClientSocketMgr.cs プロジェクト: rab000/kbhook
        //连接(成功)后操作
        private void OnConnect(System.IAsyncResult ar)
        {
            try
            {
                if (_Socket == null || !_Socket.Connected)
                {
                    Debug.Log("SocketClient.OnConnect tcp connect faile! ");

                    return;
                }

                Debug.Log("SocketClient.OnConnect tcp connect success!");

                _Socket.EndConnect(ar);

                _NetworkStream = new NetworkStream(_Socket, false);

                _SocketDataMgr = new SocketPackMgr(_Socket, _NetworkStream);

                _SocketDataMgr.CloseEvent = Close;

                _SocketDataMgr.OnProcessOnMsg = OnProcessOneMsg;

                Loom.QueueOnMainThread(() =>
                {
                    OnConnectSuccess?.Invoke();
                });

                _SocketDataMgr.ReadOnceFromSocket();
            }
            catch (Exception e)
            {
                Debug.LogError("SocketClient.OnConnect exception:" + e.Message);

                Close("OnConnect exception:" + e.Message);
            }
            finally
            {
                //if (!_Socket.Connected)
                //{
                //NaTodo 内部消息
                ////####之后添加
                //XCKuaFuMessage.AutoLogin msg = new XCKuaFuMessage.AutoLogin();
                //msg.cmd = FID.CC_KUAFU_AUTOLOGIN;
                //msg.bIsReady = true;
                //NetWorkMessageResp.cmdlist.Enqueue(msg);
                //}
            }
        }
コード例 #2
0
 public ServerSession(string ipPort, Socket socket, NetworkStream networkStream)
 {
     ID             = ipPort;
     _SocketPackMgr = new SocketPackMgr(socket, networkStream);
 }