Beispiel #1
0
    /// <summary>
    /// Q3 TCP的发送消息函数
    /// </summary>
    /// <param name="id">协议id,参看Protocal.cs</param>
    /// <param name="args">若干参数,参看MsgParse来Push参数</param>
    public void Send(byte id, params object[] args)
    {
        Q3Packet msg = new Q3Packet();

        byte[] buffer = new byte[0];
        MsgParse.PushByte(id, ref buffer);
        foreach (var arg in args)
        {
            if (arg is byte)
            {
                MsgParse.PushByte((byte)arg, ref buffer);
            }
            else if (arg is string)
            {
                MsgParse.PushString((string)arg, ref buffer);
            }
            else if (arg is int)
            {
                MsgParse.PushInt((int)arg, ref buffer);
            }
        }

        msg.SetArgs(buffer);
        channel.Send(msg);
        Log.Debug("->>>>>>>>>>>>{0},{1}", id, args);
    }