Пример #1
0
        public void SendMsg(int cmd, int scmd, BaseMessageData body)
        {
            MessageData <BaseMessageData> data = new MessageData <BaseMessageData> ();
            HeadMsg head = new HeadMsg();

            head.cmd  = cmd;
            head.scmd = scmd;
            data.head = head;
            data.body = body;
            ByteBuffer _buff = new ByteBuffer();

            byte[] bytes = data.ToBytes();
            _buff.WriteInt32(bytes.Length);
            _buff.WriteBytes(bytes);
            bytes = _buff.ToBytes();
            switch (Main.Self.clientType)
            {
            case ClientType.client:
                Main.Self.client.Send(bytes);
                break;

            case ClientType.server:
                Main.Self.server.Send(bytes);
                break;

            case ClientType.NULL:
                break;

            default:
                break;
            }
        }
Пример #2
0
        public static void SendMsg(int cmd, int scmd, ByteBuffer buffer)
        {
            MessageData sendMsg = new MessageData();
            HeadMsg     head    = new HeadMsg();

            head.cmd     = cmd;
            head.scmd    = scmd;
            sendMsg.head = head;
            sendMsg.data = buffer.ToBytes();
            byte[]     bytes      = ProtoBufTools.Serialize(sendMsg);
            ByteBuffer sendBuffer = new ByteBuffer();

            sendBuffer.WriteInt32(bytes.Length);
            sendBuffer.WriteBytes(bytes);
            bytes = sendBuffer.ToBytes();
            socket.Send(bytes);
        }