Beispiel #1
0
        public NetByteBuffer Copy()
        {
            NetByteBuffer buffer = CreateWithSize(this.DataCount);

            buffer.Write(this.sourceArray, 0, this.DataCount);

            return(buffer);
        }
Beispiel #2
0
        public void Close()
        {
            if (isConnected && msocket != null)
            {
                LogMgr.Log("close Socket");
                CloseSocket();

                if (buffer != null)
                {
                    buffer.Dispose();
                    buffer = null;
                }

                isConnected = false;

                selfip    = null;
                selfport  = 0;
                logicLock = 0;
            }
        }
Beispiel #3
0
        public static NetByteBuffer CreateWithBytes(byte[] bys)
        {
            NetByteBuffer buffer = null;

            if (KObjectPool.mIns != null)
            {
                buffer = KObjectPool.mIns.Pop <NetByteBuffer>();
                if (buffer != null)
                {
                    buffer._ResetWithBytes(bys);
                }
            }

            if (buffer == null)
            {
                buffer = new NetByteBuffer(bys);
            }

            return(buffer);
        }
Beispiel #4
0
        public override void SendMessage(NetMessage msg, Action <NetMessage> msgCallback = null)
        {
            if (isConnected)
            {
                TcpMessage tcpmsg = msg as TcpMessage;
                if (tcpmsg != null)
                {
                    byte[]        netmsg = tcpmsg.Serialize();
                    NetByteBuffer buffer = NetByteBuffer.CreateWithSize(netmsg.Length + 10);

                    netmsg = this.WriteHead(buffer, tcpmsg, netmsg);

                    if (netmsg != null && netmsg.Length > 0)
                    {
                        if (!msg.IgnoreResp)
                        {
                            sendQueue.Add(new KeyValuePair <float, int>(tcpmsg.getSendTime(), tcpmsg.SubCmd));
                        }

                        //LogMgr.LogFormat("发送消息 :{0}", tcpmsg);
                        msocket.BeginSend(netmsg, 0, netmsg.Length, SocketFlags.None, SendCallback, null);
                    }
                    else
                    {
                        LogMgr.LogError(" TcpMessage Serialize error");
                    }
                }
                else
                {
                    LogMgr.LogError("Not TcpMessage");
                }
            }
            else
            {
                LogMgr.LogError("tcp connected not yield");
            }
        }
Beispiel #5
0
        public static NetByteBuffer CreateWithSize(int size)
        {
            NetByteBuffer buffer = null;

            if (KObjectPool.mIns != null)
            {
                buffer = KObjectPool.mIns.Pop <NetByteBuffer>();
            }

            if (buffer == null)
            {
                buffer = new NetByteBuffer(size);
            }
            else
            {
                if (buffer.capacity < size)
                {
                    buffer.Resize(size);
                }

                buffer._Reset();
            }
            return(buffer);
        }
Beispiel #6
0
 public abstract void DeSerialize(NetByteBuffer buffer);
Beispiel #7
0
 protected virtual void DispatcherPkg(NetByteBuffer tempBuffer)
 {
     //read head
 }
Beispiel #8
0
 protected virtual byte[] WriteHead(NetByteBuffer buffer, TcpMessage tcpmsg, byte[] body)
 {
     return(null);
 }