示例#1
0
        public string Login(string ip, int port)
        {
            string strResult = string.Empty;

            if (!NetHelper.Connect(socket, ip, port))
            {
                strResult = "连接失败";
            }
            else
            {
                byte[] buff;
                Coder.EncodeLogin1(out buff);
                socket.Send(buff);

                byte[]           buffReceive = new byte[BUFFER_SIZE];
                int              byteBuff    = socket.Receive(buffReceive);
                NormalDataStruct dataInfo    = Coder.DecodeData(buffReceive);
                Login1Struct     loginInfo   = Coder.DecodeLogin1(dataInfo.Content);

                Coder.EncodeLogin2(out buff);
                socket.Send(buff);
                byteBuff = socket.Receive(buffReceive);
                dataInfo = Coder.DecodeData(buffReceive);
                enumRespResult loginResult = Coder.DecodeResult(dataInfo.Content);
                if (loginResult != enumRespResult.Success)
                {
                    strResult = loginResult.ToString();
                }
                else
                {
                    Coder.EncodePlayVedio(out buff);
                    socket.Send(buff);
                    byteBuff = socket.Receive(buffReceive);
                    dataInfo = Coder.DecodeData(buffReceive);
                    enumRespResult playResult = Coder.DecodeResult(dataInfo.Content);

                    if (playResult != enumRespResult.Success)
                    {
                        strResult = playResult.ToString();
                    }
                    else
                    {
                        connectFlag = true;
                        //byte[] buffVedio = new byte[] { };
                        //while (true)
                        //{
                        //    buffVedio = this.PlayVideo(buffVedio);
                        //}
                    }
                }
                //string strMsg = ConvertHelper.BytesToString(buff, System.Text.Encoding.UTF8);
                //Console.WriteLine(strMsg);
            }
            return(strResult);
        }
示例#2
0
        public static Login1Struct DecodeLogin1(byte[] data)
        {
            Login1Struct login1 = new Login1Struct();

            login1.Length = data[0];
            int len = (login1.Length + 7) / 8 * 8;

            byte[] codeInfo = new byte[data.Length - 1];
            Array.Copy(data, 1, codeInfo, 0, codeInfo.Length);
            //Console.WriteLine(ConvertHelper.BytesToString(codeInfo, Encoding.ASCII));
            if (!fish.Decode(codeInfo, len, FISH_KEY))
            {
                Console.WriteLine("解码失败");
            }
            //Console.WriteLine(codeInfo);
            login1.Plain = ConvertHelper.BytesToString(codeInfo, Encoding.ASCII);
            login1.Plain = login1.Plain.Substring(0, login1.Length - 1);
            //Console.WriteLine(login1.Plain);
            return(login1);
        }