示例#1
0
 internal void Connect(string host, int port, IClientListener listener)
 {
     if (m_Dispose)
     {
         throw new ObjectDisposedException("ClientChannel already disposed!");
     }
     m_Listener  = listener;
     m_Transport = new ClientTransport();
     m_Transport.Connect(host, port);
     RegisterMessages();
 }
示例#2
0
 public override void Dispose()
 {
     if (m_Dispose)
     {
         return;
     }
     m_Dispose = true;
     m_Transport.Dispose();
     ClearMsgHandlers();
     m_Listener  = null;
     m_Transport = null;
 }
        public void RecvReliablePackets(ClientTransport transport, KcpCon kcp, List <Packet> packets, ClientHeartbeatProcessing heartbeat)
        {
            while (true)
            {
                int size = kcp.Recv(m_Buffer, 0, m_Buffer.Length);

                if (size <= 0)
                {
                    break;
                }

                if (size == 8)
                {
                    ByteReadMemory memory = new ByteReadMemory(m_Buffer, 0, 8);
                    uint           flag   = memory.ReadUInt();
                    uint           conv   = memory.ReadUInt();

                    if (conv == kcp.Conv)
                    {
                        if (flag == KcpConstants.Flag_Heartbeat)
                        {
                            heartbeat.RecvHeartbeat();
                            continue;
                        }

                        if (flag == KcpConstants.Flag_Disconnect)
                        {
                            transport.Disconnect(false, true);
                            continue;
                        }
                    }
                }

                PacketProcessing.Recv(m_Buffer, 0, size, packets);
            }
        }