コード例 #1
0
ファイル: MyClientSoc.cs プロジェクト: cherip/csharpgame
        //public bool SendMsg(MsgSys msg)
        //{
        //    Message fullMsg = new Message(msg);
        //    return SendMsg(fullMsg);
        //}

        //public bool SendMsg(MsgGame msg)
        //{
        //    Message fullMsg = new Message(msg);
        //    return SendMsg(fullMsg);
        //}

        //public bool SendMsg(MsgChat msg)
        //{
        //    Message fullMsg = new Message(msg);
        //    return SendMsg(fullMsg);
        //}

        public bool SendMsg(Message msg)
        {
            try
            {
                Byte[] outbytes = SerializationUnit.SerializeObject(msg);

                //加密数据
                Byte[] enbytes = DES.Enbyte(outbytes, outbytes.Length);
                //ns.Write(outbytes, 0, outbytes.Length);
                ns.Write(enbytes, 0, enbytes.Length);

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(false);
            }
        }
コード例 #2
0
ファイル: MyClientSoc.cs プロジェクト: cherip/csharpgame
        public Message RecieveMsg()
        {
            try
            {
                byte[] byteMessage = new byte[1024];
                int    msglen      = ns.Read(byteMessage, 0, byteMessage.Length);

                //解密数据
                Byte[] realDate = new Byte[msglen];
                System.Buffer.BlockCopy(byteMessage, 0, realDate, 0, msglen);
                Byte[] realDateDeCode = DES.Debyte(realDate, msglen);

                //  Message msg = (Message)(SerializationUnit.DeserializeObject(byteMessage));
                Message msg = (Message)(SerializationUnit.DeserializeObject(realDateDeCode));
                return(msg);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(null);
            }
        }