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); }
public static enumRespResult DecodeResult(byte[] data) { enumRespResult result = (enumRespResult)data[0]; return(result); }