Example #1
0
        public void Send(int id, string name, LuaTable tb)
        {
            if (SocketClient.State == SocketClient.ConnectState.DisConnect)
            {
                return;
            }
            var msg = ProtocolGroup.GetMsg(name);

            if (msg == null)
            {
                Debug.Log(String.Format("protocol {0} not exist", name));
                return
            }

            m_messageIndex++;
            ByteBuffer protoBuff = new ByteBuffer();

            ProtocolReadWriter.Req(msg.Id, buff, tb, ProtocolGroup);
            byteBuffer buff = new ByteBuffer();

            buff.WriteUshort(msg.Id);
            buff.WriteBytes(protoBuff.ToBytes());
            protoBuff.Close();

            byte[]     buffBytes   = buff.ToBytes();
            ByteBuffer contentBuff = new ByteBuffer();

            contentBuff.WriteVchar((uint)buffBytes.Length);
            contentBuff.WriteBytes(buffBytes);

            ByteBuffer sendBuff = new ByteBuffer();

            sendBuff.WriteUint(Convert.ToUInt32(buffBytes.Length) + 16);

            //CRC
            uint crc = CRC.GetCrc32(buffBytes);

            sendBuffer.WriteUint(crc);

            //Time
            uint       timeUint = TimeSpanUtils.ConvertDateTimeToUInt(DateTime.Now);
            ByteBuffer desBuff  = new ByteBuffer();

            desBuff.WriteBytes(BitConverter.GetBytes(timeUint));
            desBuff.WriteBytes(BitConverter.GetBytes(m_messageIndex));

            //DES
            ulong des = BitConverter.ToUInt64(desBuff.ToBytes(), 0);

            byte[] desBytes = DES.Encrypt(bitConverter.GetBytes(des));

            sendBuff.WriteUlong(BitConverter.ToUInt64(desBytes, 0));
            sendBuff.WriteBytes(buffBytes);
            client.SendMessage(sendBuff);

            contentBuff.Close();
            desBuff.Close();
            buff.Close();
        }
Example #2
0
        public void SendMessage(string str_protoId, ByteBuffer buffer)
        {
            byte[] data    = buffer.ToBytes();
            int    protoId = int.Parse(str_protoId.Trim());

            Debug.LogError(protoId + ":" + data.Length);
            m_clientSocket.Send(data, protoId);
        }
Example #3
0
        /*
         * /// <summary>
         * /// 发送SOCKET消息
         * /// </summary>
         * public void SendMessage(ByteBuffer buffer)
         * {
         *  //if (buffer != null)
         *  //{
         *  //    ushort id = buffer.ReadShort();
         *  //    Debug.LogError("id:" + id);
         *  //}
         *  //else
         *  //{
         *  //    Debug.LogError("buffer null");
         *  //}
         *  //byte[] data = buffer.ToBytes();
         *  //Debug.LogError("net work send!!" + data.Length);
         *  //ByteBuffer buf = new ByteBuffer(data);
         *  //ushort protoId = buf.ReadShort();
         *  //Debug.LogError("protoId:" + protoId);
         *  //byte[] data2 = buf.ToBytes();
         *  //Debug.LogError("datasize:" + data2.Length);
         *  // m_clientSocket.Send(data2, protoId);
         * }
         */

        public void SendMessage(string str_protoId, ByteBuffer buffer)
        {
            byte[] data    = buffer.ToBytes();
            int    protoId = int.Parse(str_protoId.Trim());
            string str     = String.Format("发送:ProtoId:{0},数据内容字节数(不含包头):{1}", protoId, data.Length);

            Debug.Log(str);
            m_clientSocket.Send_QiPai(protoId, data);
        }
Example #4
0
    protected void SetActionHead(int actionId, LuaFramework.ByteBuffer body)
    {
        //writer.writeInt32("actionId", ActionId);
        byte[]     bodyBuffer = body.ToBytes();
        ByteBuffer headBuffer = new ByteBuffer();

        headBuffer.WriteInt(actionId);
        headBuffer.WriteInt(bodyBuffer.Length);
        headBuffer.WriteInt(NetWriter.MsgId - 1);
        headBuffer.WriteInt(0); //body_check;
        headBuffer.WriteInt(0); //head_check;

        NetWriter.Instance.SetHeadBuffer(headBuffer.ToBytes());
    }
 static int ToBytes(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1);
         byte[] o = obj.ToBytes();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #6
0
        void test()
        {
            ByteBuffer temp = new ByteBuffer();

            temp.WriteString("UTF-8 现在是测试随便传");
            temp.WriteString("Hello world");
            temp.WriteInt(108);
            //temp.Close();

            ByteBuffer tempR = new ByteBuffer(temp.ToBytes());

            //Debug.Log(tempR.ReadInt());
            //Debug.Log(tempR.ReadString());
            LuaManager.CallLuaFunction <int, ByteBuffer>("Network.OnSocket", 19000, tempR);
            //LuaManager.DoFile("ui/test/test");
            //Util.CallMethod("Test", "FuncTest", tempR);     //初始化完成
        }
        /// <summary>
        /// 发送SOCKET消息
        /// </summary>
        public void SendMsg(int uMsgID, ByteBuffer buffer)
        {
            NFMsg.MsgBase xData = new NFMsg.MsgBase();
            xData.player_id = Util.NFToPB(mMainID);
            ByteBuffer newbuffer = new ByteBuffer(buffer.ToBytes());

            xData.msg_data = newbuffer.ReadBytes();
            MemoryStream body = new MemoryStream();

            Serializer.Serialize <NFMsg.MsgBase>(body, xData);
            MsgHead head = new MsgHead();

            head.unMsgID   = (UInt16)uMsgID;
            head.unDataLen = (UInt32)body.Length + (UInt32)ConstDefine.NF_PACKET_HEAD_SIZE;
            byte[] bodyByte  = body.ToArray();
            byte[] headByte  = StructureTransform.StructureToByteArrayEndian(head);
            byte[] sendBytes = new byte[head.unDataLen];
            headByte.CopyTo(sendBytes, 0);
            bodyByte.CopyTo(sendBytes, headByte.Length);
            SocketClient.SendMessage(sendBytes);
            buffer.Close();
            newbuffer.Close();
        }
Example #8
0
    private void SocketRequest(int actionId, int actionRespId, LuaFramework.ByteBuffer body, LuaInterface.LuaFunction callback, IHeadFormater formater, bool bShowLoading)
    {
        if (mSocket == null)
        {
            string   url = NetWriter.GetUrl();
            string[] arr = url.Split(new char[] { ':' });
            if (arr.Length != 2)
            {
                Debug.LogError("Url is error:" + url);
                return;
            }
            int nPort = int.Parse(arr[1]);
            mSocket = new SocketConnect(arr[0], nPort, formater);
        }

        SocketPackage package = new SocketPackage();

        package.MsgId        = NetWriter.MsgId - 1;
        package.ActionId     = actionId;
        package.ActionRespId = actionRespId;
        package.HasLoading   = bShowLoading;
        package.SendTime     = DateTime.Now;
        package.Callback     = callback;

        NetWriter writer = NetWriter.Instance;

        SetActionHead(actionId, body);
        writer.SetBodyData(body.ToBytes());
        byte[] data = writer.PostData();
        NetWriter.resetData();

        if (bShowLoading)
        {
            RequestDelegate(Status.eStartRequest);
        }
        mSocket.Send(data, package);
    }
Example #9
0
        /// <summary>
        /// 发送SOCKET消息
        /// </summary>
        public void SendMessage(ByteBuffer buffer)
        {
            //if (buffer != null)
            //{
            //    ushort id = buffer.ReadShort();
            //    Debug.LogError("id:" + id);
            //}
            //else
            //{
            //    Debug.LogError("buffer null");
            //}


            byte[] data = buffer.ToBytes();
            Debug.LogError("net work send!!" + data.Length);

            //ByteBuffer buf = new ByteBuffer(data);
            //ushort protoId = buf.ReadShort();
            //Debug.LogError("protoId:" + protoId);
            //byte[] data2 = buf.ToBytes();
            //Debug.LogError("datasize:" + data2.Length);

            // m_clientSocket.Send(data2, protoId);
        }
Example #10
0
 /// <summary>
 /// 发送消息
 /// </summary>
 public void SendMessage(LuaFramework.ByteBuffer buffer)
 {
     SessionSend(buffer.ToBytes());
     buffer.Close();
 }
Example #11
0
 /// <summary>
 /// 发送SOCKET消息,可以考虑从池中取出ByteBuffer
 /// </summary>
 public void Send(ByteBuffer buffer)
 {
     m_socket.Send(buffer.ToBytes());
 }
Example #12
0
 public void SendTcpClientMessage(UInt16 protoid, ByteBuffer buffer)
 {
     networkCtrl.SendMessage(mTcpClientSessionId, protoid, buffer.ToBytes());
 }