Ejemplo n.º 1
0
        public ByteArray signByteStream(ByteArray byteBuffer)
        {
            //* <p>[4字节] 长度
            //* <p>[1字节] 校验码
            //* <p>[1字节] 循环顺序号(从0开始,每次请求+1,不符合则断开; 0,1,2,...,127,-128,-127,...,-1,0,1,...)
            //* <p>[1字节] 模块号
            //* <p>[1字节] 命令号
            //包头长度 8 字节
            //self.netSendPackVStream:writeInt8(packet.req['_MOD_'])
            //self.netSendPackVStream:writeInt8(packet.req['_MED_'])
            //self.netSendPackVStream:writeInt32(0)--预留六字节
            //self.netSendPackVStream:writeInt16(0)
            byte[] data         = byteBuffer.getBuffer();
            int    len          = data.Length;
            byte   module       = byteBuffer.readInt8();
            byte   method       = byteBuffer.readInt8();
            short  validateCode = fnvhash(m_sn, module, method, len);

            ByteArray buf = new ByteArray();

            buf.writeInt32(Endian.SwapInt32(len));
            buf.writeInt8((byte)validateCode);
            buf.writeInt8((byte)m_sn);
            buf.writeInt8(module);
            buf.writeInt8(method);

            byte[] bytes = new byte[len - 8];
            Buffer.BlockCopy(data, 8, bytes, 0, len - 8);
            buf.writeBytes(bytes);

            m_sn++;

            return(buf);
        }
Ejemplo n.º 2
0
        public void writeString(string s)
        {
            short len = (short)s.Length;

            writeInt16(len);
            byte[] val = System.Text.Encoding.Default.GetBytes(s);
            m_pBuffer.writeBytes(val);
        }
Ejemplo n.º 3
0
        public ByteArray copyBufferPart(int startIndex, int nCount)
        {
            ByteArray buffer = new ByteArray();

            byte[] ByteArray = new byte[nCount];

            Buffer.BlockCopy(m_buffer, startIndex, ByteArray, 0, nCount);

            buffer.writeBytes(ByteArray);

            return(buffer);
        }
Ejemplo n.º 4
0
        public ByteArray copyBufferAll()
        {
            ByteArray buffer = new ByteArray();

            int byteLen = dataSize() - dataPtr();

            byte[] ByteArray = new byte[byteLen];

            Buffer.BlockCopy(m_buffer, m_nHeadOffset, ByteArray, 0, byteLen);

            buffer.writeBytes(ByteArray);

            return(buffer);
        }
Ejemplo n.º 5
0
	static int writeBytes(IntPtr L)
	{
		try
		{
			ToLua.CheckArgsCount(L, 2);
			NetCore.ByteArray obj = (NetCore.ByteArray)ToLua.CheckObject(L, 1, typeof(NetCore.ByteArray));
			byte[] arg0 = ToLua.CheckByteBuffer(L, 2);
			obj.writeBytes(arg0);
			return 0;
		}
		catch(Exception e)
		{
			return LuaDLL.toluaL_exception(L, e);
		}
	}
Ejemplo n.º 6
0
 private void _recvData()
 {
     try
     {
         if (_socket.Poll(5, SelectMode.SelectRead))
         {
             byte[] prefix = new byte[4]; //包长度
             int    recnum = _socket.Receive(prefix);
             if (recnum == 4)
             {
                 int len = BitConverter.ToInt32(prefix, 0);
                 //int l = Endian.s
                 int    datalen    = Endian.SwapInt32(len) - 4;
                 byte[] data       = new byte[datalen];
                 int    startIndex = 0;
                 recnum = 0;
                 do
                 {
                     int rev = _socket.Receive(data, startIndex, datalen - recnum, SocketFlags.None);
                     recnum     += rev;
                     startIndex += rev;
                 } while (recnum != datalen);
                 ByteArray buffer = new ByteArray();
                 //buffer.WriteBytes(prefix);
                 buffer.writeBytes(data);
                 lock (_receiveQueue)
                 {
                     _receiveQueue.pushBack(buffer);
                 }
             }
         }
         else if (_socket.Poll(5, SelectMode.SelectError))
         {
             shutdownNet();
             UnityEngine.Debug.Log("SelectError Close Socket");
         }
     }
     catch (Exception)
     {
         Debug.Log("_recvData wtf");
     }
 }
Ejemplo n.º 7
0
        public ByteArray signByteStream(byte module, byte method, byte[] data)
        {
            //* <p>[4字节] 长度
            //* <p>[1字节] 校验码
            //* <p>[1字节] 循环顺序号(从0开始,每次请求+1,不符合则断开; 0,1,2,...,127,-128,-127,...,-1,0,1,...)
            //* <p>[1字节] 模块号
            //* <p>[1字节] 命令号
            //包头长度 8 字节
            int   len          = data.Length + 8;
            short validateCode = fnvhash(m_sn, module, method, len);

            ByteArray byteBuffer = new ByteArray();

            byteBuffer.writeInt32(Endian.SwapInt32(len));
            byteBuffer.writeInt8((byte)validateCode);
            byteBuffer.writeInt8((byte)m_sn);
            byteBuffer.writeInt8(module);
            byteBuffer.writeInt8(method);
            byteBuffer.writeBytes(data);

            m_sn++;

            return(byteBuffer);
        }