public PacketReceiverKCP(NetworkInterfaceBase networkInterface) : base(networkInterface)
        {
            _buffer        = new byte[MessageLength.MaxValue + (Deps.KCP.IKCP_OVERHEAD * 2)];
            _messageReader = new MessageReaderKCP();

            kcp_ = ((NetworkInterfaceKCP)networkInterface).kcp();
        }
Ejemplo n.º 2
0
        public void send(NetworkInterfaceBase networkInterface)
        {
            fini(true);

            if (networkInterface.valid())
            {
                for (int i = 0; i < streamList.Count; i++)
                {
                    MemoryStream tempStream = streamList[i];
                    networkInterface.send(tempStream);
                }
            }
            else
            {
                Dbg.ERROR_MSG("Bundle::send: networkInterface invalid!");
            }

            // 把不用的MemoryStream放回缓冲池,以减少垃圾回收的消耗
            for (int i = 0; i < streamList.Count; ++i)
            {
                streamList[i].reclaimObject();
            }

            streamList.Clear();
            stream.clear();

            // 我们认为,发送完成,就视为这个bundle不再使用了,
            // 所以我们会把它放回对象池,以减少垃圾回收带来的消耗,
            // 如果需要继续使用,应该重新Bundle.createObject(),
            // 如果外面不重新createObject()而直接使用,就可能会出现莫名的问题,
            // 仅以此备注,警示使用者。
            Bundle.reclaimObject(this);
        }
Ejemplo n.º 3
0
        public PacketSenderTCP(NetworkInterfaceBase networkInterface) : base(networkInterface)
        {
            _buffer = new byte[KBEngineApp.app.getInitArgs().TCP_SEND_BUFFER_MAX];

            _wpos    = 0;
            _spos    = 0;
            _sending = false;
        }
 public PacketSenderKCP(NetworkInterfaceBase networkInterface) : base(networkInterface)
 {
     socket_        = _networkInterface.sock();
     remoteEndPint_ = ((NetworkInterfaceKCP)_networkInterface).remoteEndPint;
 }
 public PacketReceiverTCP(NetworkInterfaceBase networkInterface) : base(networkInterface)
 {
     _buffer        = new byte[KBEngineApp.app.getInitArgs().TCP_RECV_BUFFER_MAX];
     _messageReader = new MessageReaderTCP();
 }
 public PacketReceiverBase(NetworkInterfaceBase networkInterface)
 {
     _networkInterface = networkInterface;
 }
 public PacketSenderBase(NetworkInterfaceBase networkInterface)
 {
     _networkInterface = networkInterface;
     _asyncSendMethod  = new AsyncSendMethod(this._asyncSend);
     _asyncCallback    = new AsyncCallback(_onSent);
 }