예제 #1
0
        private static bool _SampleMsgCreater(UInt16 id, ref CSLib.Framework.CMessage msg)
        {
            Message.EMsgID msgID = (Message.EMsgID)id;
            switch (msgID)
            {
            case Message.EMsgID.EMID_SAMPLE_NTF_OK:
            {
                msg = new Message.CMsgSampleNtfOk();
                return(true);
            }

            case Message.EMsgID.EMID_SAMPLE_REQ_SAY:
            {
                msg = new Message.CMsgSampleReqSay();
                return(true);
            }

            case Message.EMsgID.EMID_SAMPLE_RES_SAY:
            {
                msg = new Message.CMsgSampleResSay();
                return(true);
            }
            }
            return(false);
        }
예제 #2
0
        static void Main(string[] args)
        {
            CSLib.Network.CTcpClient tcpClient = new CSLib.Network.CTcpClient();

            CClientMsg clientMsg = new CClientMsg(tcpClient);

            tcpClient.CbParsMsg      = clientMsg.ParseMsg;
            tcpClient.CbTerminateMsg = CClientMsg.TerminateMsg;

            if (!tcpClient.Connect("127.0.0.1", 9500))
            {
                Console.WriteLine("连接服务器失败");
                return;
            }
            Message.CMsgSampleNtfOk ntfOk = new Message.CMsgSampleNtfOk();

            CSLib.Utility.CStream stream = new CSLib.Utility.CStream();
            ntfOk.Serialize(stream);
            if (!tcpClient.SendAsync(stream))
            {
                return;
            }

            stream.Reset();
            Console.WriteLine(tcpClient.LocalIPEndPoint.ToString() + "--->" + tcpClient.PeerIPEndPoint.ToString());

            uint i = 1;

            //DateTime dt = new DateTime(2013,3,4);
            // decimal dec = 12.12M;
            while (true)
            {
                stream.Reset();

                Message.CMsgSampleReqSay reqSay = new Message.CMsgSampleReqSay();

                reqSay.m_string  = "Client No.[";
                reqSay.m_string += i.ToString();
                reqSay.m_string += "]";
                byte[] vv;
                vv              = new byte[5];
                vv[1]           = 1;
                vv[2]           = 2;
                vv[3]           = 3;
                vv[4]           = 4;
                vv[0]           = 5;
                reqSay.m_bool   = true;
                reqSay.m_byte   = (byte)i;
                reqSay.m_bytes  = vv;
                reqSay.m_double = 1213.43435;
                reqSay.m_float  = 123.234f;
                reqSay.m_int    = 34534534;
                reqSay.m_long   = 3245675756675L;
                reqSay.m_short  = 32000;
                reqSay.m_uint   = 2100000000;
                reqSay.m_ulong  = 94242424242342L;
                reqSay.m_ushort = 65000;
                reqSay.Serialize(stream);

                i++;

                Console.WriteLine(reqSay.m_string + reqSay.m_bool + "  " + reqSay.m_byte + "  " + reqSay.m_bytes[0] + "  " + reqSay.m_bytes[1] + "  " + reqSay.m_bytes[2] + "  " + reqSay.m_bytes[3] + "  " + reqSay.m_bytes[4] + "  " + reqSay.m_double + "  " + reqSay.m_float + "  " + reqSay.m_int + "  " + reqSay.m_long + "  " + reqSay.m_short + "  " + reqSay.m_uint + "  " + reqSay.m_ulong + "  " + reqSay.m_ushort);

                if (!tcpClient.SendAsync(stream))
                {
                    break;
                }

                stream.Reset();

                System.Threading.Thread.Sleep(1000);
            }
        }