Exemplo n.º 1
0
        private void OnDisconnect(object sender, TcpConnection.TcpConnectionArgs e)
        {
            Player player = new Player(Account, Number, e.Connection);
            var    args   = new PlayerArg
            {
                Player = player
            };

            OnDisconnectEvent?.Invoke(this, args);
        }
Exemplo n.º 2
0
        public void Disconnect()
        {
            UpdateManager.StopUdpUpdates();

            _tcpNetClient.Disconnect();
            _udpNetClient.Disconnect();

            IsConnected = false;

            // Invoke callback if it exists
            OnDisconnectEvent?.Invoke();
        }
Exemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (isConnected)
     {
         lock (thisLock) {
             if (disconnected)
             {
                 socketConnection = null;
                 closeEvent.Set();
                 RecvedPackets.Clear();
                 if (OnDisconnectEvent != null)
                 {
                     OnDisconnectEvent.Invoke();
                 }
                 isConnected  = false;
                 disconnected = false;
             }
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 新建连接
        /// </summary>
        /// <param name="ip">连接的服务器IP</param>
        /// <param name="port">连接的端口号</param>
        /// <param name="connEvent">连接完成后回调</param>
        /// <param name="disconnEvent">断开连接发生时回调</param>
        /// <param name="recvEvent">接收到消息包时回调</param>
        public void Connect(string ip, int port, OnConnectEvent connEvent, OnDisconnectEvent disconnEvent, OnRecvEvent recvEvent)
        {
            if (mIsConnected)
            {
                Disconnect("reconnect");
            }

            mOnConnect     = connEvent;
            mOnDisConnect  = disconnEvent;
            mOnRecvPackage = recvEvent;
            mIP            = ip;
            mPort          = port;

            mTcpClient = new TcpClient
            {
                NoDelay           = true,
                ReceiveBufferSize = mRecvBuffSize,
                SendBufferSize    = mSendBuffSize
            };

            mIsConnected = false;

            try
            {
                mTcpClient.BeginConnect(IPAddress.Parse(ip), port, new AsyncCallback(OnConnectCallback), mTcpClient);

                Invoke("ConnectTimeOutCheck", 3);
            }
            catch (Exception ex)
            {
                if (IsInvoking("ConnectTimeOutCheck"))
                {
                    CancelInvoke("ConnectTimeOutCheck");
                }

                if (mOnConnect != null)
                {
                    mOnConnect.Invoke(false, ex.ToString());
                }
            }
        }
        public void HandleEvents()
        {
            lock (netEventQueue)
            {
                while (netEventQueue.Count != 0)
                {
                    NetEvent netEvent = netEventQueue.Dequeue();

                    switch (netEvent.type)
                    {
                    case ENet.EventType.None:
                        break;

                    case ENet.EventType.Connect:
                    {
                        isConnected = true;
                        OnConnect();
                        OnConnectEvent?.Invoke();
                    }
                    break;

                    case ENet.EventType.Receive:
                    {
                        HandleAnyPacket(netEvent.packet);
                    }
                    break;

                    case ENet.EventType.Disconnect:
                    {
                        isConnected = false;
                        OnDisconnect();
                        OnDisconnectEvent?.Invoke();
                    }
                    break;
                    }
                }
            }
        }
Exemplo n.º 6
0
 public override void OnDisconnect(int reasonCode)
 {
     OnDisconnectEvent?.Invoke(reasonCode);
 }
Exemplo n.º 7
0
 public void Disconnect(SocketInput input, SocketOutput output)
 {
     connectedOutputs.Remove(output);
     OnDisconnectEvent?.Invoke(input, output);
 }
Exemplo n.º 8
0
 public override void OnDisconnected(DisconnectCause cause)
 {
     OnDisconnectEvent?.Invoke();
 }
Exemplo n.º 9
0
    protected override void OnDisconnect()
    {
        Debug.Log("Disconnected");

        OnDisconnectEvent.Invoke();
    }