//发送消息 /// <summary> /// 发送消息 /// 2013-05-19 jxb /// 传入数据体,组成数据帧 /// </summary> /// <summary> /// public virtual void SendMessage(byte[] datagram, UInt16 MsgId, string centercode) { //|5b|4-4-2-4|..........|2|5d| == 18 // //获取消息数据 // byte[] data = System.Text.Encoding.UTF8.GetBytes(datagram); //string str = System.Text.Encoding.UTF8.GetString(data); TastInfo info = new TastInfo(); byte[] msg = new byte[18 + datagram.Length]; msg[0] = 0x5b;//头 MSGHEAD head = new MSGHEAD(); head.Msg_ID = MsgId; head.Msg_Length = (UInt32)msg.Length; head.Msg_GNSSCenter = UInt32.Parse(centercode); //头数据 byte[] Head = info.StructureToByteArrayEndian(head); datagram.CopyTo(msg, 15); Head.CopyTo(msg, 1); //加入CRC校验5 msg[msg.Length - 1] = 0x5d;//尾 _session.ClientSocket.BeginSend(msg, 0, msg.Length, SocketFlags.None, new AsyncCallback(SendDataEnd), _session.ClientSocket); }
//发送消息 /// <summary> /// 发送消息 /// 2013-05-19 jxb /// 传入数据体,组成数据帧 /// </summary> /// <summary> /// public virtual void SendMessage(Session recvDataClient, string datagram, UInt16 MsgId, string centercode) { //|5b|4-4-2-4|..........|2|5d| == 18 // byte[] data = Encoding.UTF8.GetBytes(datagram); //获取消息 byte[] msg = new byte[18 + data.Length]; msg[0] = 0x5b; //头 MSGHEAD head = new MSGHEAD(); head.Msg_ID = MsgId; head.Msg_Length = (UInt32)msg.Length; head.Msg_GNSSCenter = UInt32.Parse(centercode);; TastInfo info = new TastInfo(); byte[] Head = info.StructureToByteArrayEndian(head); // 将结构转换成字节数组大端 data.CopyTo(msg, 15); Head.CopyTo(msg, 1); //加入CRC校验5 byte[] crcbuf = new byte[msg.Length - 4]; Array.Copy(crcbuf, 0, msg, 1, (uint)crcbuf.Length); msg[msg.Length - 1] = 0x5d;//尾 recvDataClient.ClientSocket.BeginSend(msg, 0, msg.Length, SocketFlags.None, new AsyncCallback(SendDataEnd), recvDataClient.ClientSocket); }
public bool UpLoad(byte[] buffer, string deviceid) { DETECTION_INFO detInfo = new DETECTION_INFO();//共计866字节 object detinfoType = detInfo; TastInfo Tinfo = new TastInfo(); Tinfo.ByteArrayToStructureEndian(buffer, ref detinfoType, 0); detInfo = (DETECTION_INFO)detinfoType; //写入数据库 string batch_id = System.Text.Encoding.UTF8.GetString(detInfo.batch_id, 0, GetLen(detInfo.batch_id)).Trim(); string task_id = System.Text.Encoding.UTF8.GetString(detInfo.task_id, 0, GetLen(detInfo.task_id)).Trim(); // UInt64 batch_id = detInfo.batch_id; // UInt32 task_id = detInfo.task_id; string p_name = System.Text.Encoding.UTF8.GetString(detInfo.p_name, 0, GetLen(detInfo.p_name)).Trim(); string type = System.Text.Encoding.UTF8.GetString(detInfo.type, 0, GetLen(detInfo.type)); int channel = (int)detInfo.channel; string ftest_result = System.Text.Encoding.UTF8.GetString(detInfo.ftest_result, 0, GetLen(detInfo.ftest_result)).Trim(); string test_result = System.Text.Encoding.UTF8.GetString(detInfo.test_result, 0, GetLen(detInfo.test_result)).Trim(); string result_unit = System.Text.Encoding.UTF8.GetString(detInfo.result_unit, 0, GetLen(detInfo.result_unit)).Trim(); string standard = System.Text.Encoding.UTF8.GetString(detInfo.standard, 0, GetLen(detInfo.standard)).Trim(); string abs_result = System.Text.Encoding.UTF8.GetString(detInfo.abs_result, 0, GetLen(detInfo.abs_result)).Trim(); string sample_no = System.Text.Encoding.UTF8.GetString(detInfo.sample_no, 0, GetLen(detInfo.sample_no)).Trim(); string sample_name = System.Text.Encoding.UTF8.GetString(detInfo.sample_name, 0, GetLen(detInfo.sample_name)).Trim(); string sites = System.Text.Encoding.UTF8.GetString(detInfo.sites, 0, GetLen(detInfo.sites)).Trim(); string submission_unit = System.Text.Encoding.UTF8.GetString(detInfo.submission_unit, 0, GetLen(detInfo.submission_unit)).Trim(); string test_operator = System.Text.Encoding.UTF8.GetString(detInfo.test_operator, 0, GetLen(detInfo.test_operator)).Trim(); string test_unit = System.Text.Encoding.UTF8.GetString(detInfo.test_unit, 0, GetLen(detInfo.test_unit)).Trim(); string test_time = System.Text.Encoding.UTF8.GetString(detInfo.test_time, 0, GetLen(detInfo.test_time)).Trim(); // DateTime dt = DateTime.ParseExact(test_time, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); int User_Id = 1234; if (deviceid != null) { User_Id = int.Parse(deviceid); } string strsql = "Insert Into " + "detectioninfo(batch_id,task_id,p_name,type,channel,Juge_result,Detect_result,result_unit,standard,Absolut_result,sample_no,sample_name,sites,submission_unit,test_operator,test_unit,test_time,Device_ID)" + "values('" + batch_id + "','" + task_id + "','" + p_name + "','" + type + "'," + channel + ",'" + ftest_result + "','" + test_result + "','" + result_unit + "','" + standard + "','" + abs_result + "','" + sample_no + "','" + sample_name + "','" + sites + "','" + submission_unit + "','" + test_operator + "','" + test_unit + "','" + test_time + "'," + User_Id + ")"; try { dbMySql.Open(databasename); dbMySql.ExcuteNonQuery(databasename, strsql); dbMySql.Close(databasename); return(true); } catch (System.Exception ex) { return(false); } }
/// <summary> /// 获取文件头 /// </summary> static public MSGHEAD Get_MSGHeader(byte[] buffer) { // byte[] buffer = System.Text.Encoding.UTF8.GetBytes(str); TastInfo Info = new TastInfo(); MSGHEAD head = new MSGHEAD(); object headType = head; Info.ByteArrayToStructureEndian(buffer, ref headType, 0); head = (MSGHEAD)headType; return(head); }
/// <summary> /// 是否注册 /// </summary> public REGISTER IsRegest(MSGHEAD head, byte[] buf) { REGISTER regiester = new REGISTER(); TastInfo Info = new TastInfo(); Msg_LoadAsk user23 = new Msg_LoadAsk(); object user23Type = user23; Info.ByteArrayToStructureEndian(buf, ref user23Type, 0); user23 = (Msg_LoadAsk)user23Type; UInt32 nameId = user23.nameId; //此处有小问题,如何从八位bytes完整提取为string类型。2013-5-29 string password = System.Text.Encoding.UTF8.GetString(user23.password, 0, GetLen(user23.password)).Trim();// UInt32 centercode = head.Msg_GNSSCenter; DataTable table = LoadDevice(); DataRow[] dr = table.Select("Device_ID =" + nameId); //查询用户 if (dr.Length == 1) { if (dr[0]["Device_PassWord"].ToString().Equals(password)) { if (dr[0]["Device_Code"].ToString().Equals(head.Msg_GNSSCenter.ToString())) { regiester.nameId = nameId; regiester.centercode = head.Msg_GNSSCenter; regiester.result = 0x00; //验证通过 ,发送消息 } else { //接入码不对 regiester.centercode = centercode; regiester.result = 0x01; } } else { //密码不对 regiester.centercode = centercode; regiester.result = 0x03; } } else { //没有注册 regiester.centercode = centercode; regiester.result = 0x02; } return(regiester); }
protected void ReceiveData(IAsyncResult iar) { Socket client = (Socket)iar.AsyncState; try { int recv = client.EndReceive(iar); if (recv == 0) { // CloseClient(client, Session.ExitType.NormalExit); return; } string receivedData = String.Empty; if (_recvDataBuffer[0] == 0x5b) { Console.Write(">"); // Console.Write(recv); receivedData = System.Text.Encoding.UTF8.GetString(_recvDataBuffer, 0, recv - 1); // Array.Copy(_recvDataBuffer,0, rcbuffer, 0, recv - 1); if (RecvData != null) { Session sendDataSession = FindSession(client); Debug.Assert(sendDataSession != null); ICloneable copySession = (ICloneable)sendDataSession; Session clientSession = (Session)copySession.Clone(); clientSession.Datagram = receivedData; // clientSession.RvBufer = _recvDataBuffer; Array.Copy(_recvDataBuffer, clientSession.RvBufer, recv);//jxb RecvData(this, new NetEventArgs(clientSession)); } } else { Console.Write(recv); Console.Write("#"); byte[] ab = new byte[16]; Array.Copy(_recvDataBuffer, 0, ab, 0, 16); FileHeader fileinfo = new FileHeader(); TastInfo Info = new TastInfo(); object fileinfoType = fileinfo; if (FileBegine) { filename = null; _filePath = "D:\\MyVidio\\"; Info.ByteArrayToStructureEndian(ab, ref fileinfoType, 0); fileinfo = (FileHeader)fileinfoType; filename = System.Text.Encoding.UTF8.GetString(_recvDataBuffer, 16, (int)fileinfo.fileNameLng); _filePath += System.Text.Encoding.UTF8.GetString(_recvDataBuffer, 16, (int)fileinfo.fileNameLng); fs = new FileStream(_filePath, FileMode.Create); // fs.Close(); // 存数据库 TotalLng = 0; Toal = (int)(fileinfo.fileLng); FileBegine = false; string tim = System.DateTime.Now.ToString(); if (IsPic) { //更新数据库状态 string sq = "INSERT INTO picinfo (Device_ID, Pic_Name, test_time) VALUES ('" + device_id + "','" + filename + "','" + tim + "')"; database.Open(); database.ExcuteNonQuery(sq); database.Close(); } else { //更新数据库状态 string sq = "UPDATE detectioninfo SET video_path = '" + filename + "' WHERE Device_ID = '" + device_id + "'"; database.Open(); database.ExcuteNonQuery(sq); database.Close(); } TimeIndex = 0; } else { //计算当前要读取的块的大小 int currentBlockLength = 0; Console.Write("+"); Console.Write(TimeIndex++); Console.Write("\nToal=" + Toal); TotalLng += recv; if (TotalLng < Toal) { FileBegine = false; Console.Write("\nTotalLng= " + TotalLng); fs.Write(_recvDataBuffer, 0, recv); fs.Flush(); } else if (TotalLng == Toal) { fs.Write(_recvDataBuffer, 0, recv); Console.Write("ok"); FileBegine = false; filename = null; fs.Close(); } else { Console.Write("error"); FileBegine = false; filename = null; fs.Close(); } } } // Not all data received. Get more. client.BeginReceive(_recvDataBuffer, 0, _recvDataBuffer.Length, SocketFlags.None, new AsyncCallback(ReceiveData), client); } catch (SocketException ex) { //客户端退出 if (10054 == ex.ErrorCode) { //客户端强制关闭 CloseClient(client, Session.ExitType.ExceptionExit); } } catch (ObjectDisposedException ex) { //这里的实现不够优雅 //当调用CloseSession()时,会结束数据接收,但是数据接收 //处理中会调用int recv = client.EndReceive(iar); //就访问了CloseSession()已经处置的对象 //我想这样的实现方法也是无伤大雅的. if (ex != null) { ex = null; //DoNothing; } } }
void RecvData(object sender, NetEventArgs e) { // string info = string.Format("recv data:{0} from:{1}.", e.Client.Datagram, e.Client); // Console.WriteLine(info); TcpSvr svr = (TcpSvr)sender; //测试把收到的数据返回给客户端 // svr.SendText(e.Client, e.Client.Datagram); //svr.SendFile(this.textBox1.Text); // Console.Write(">"); DETECTION_INFO ff = new DETECTION_INFO(); int si = Marshal.SizeOf(ff); //获取接受到的消息,已经去头,但是包括尾 // byte[] recivebuffer = System.Text.Encoding.Default.GetBytes(e.Client.Datagram); List <Byte> lbyte = new List <Byte>(); byte[] recivebuffer = e.Client.RvBufer; for (int k = 0; k < e.Client.RvBufer.Length - 1; k++) { byte b = e.Client.RvBufer[k]; byte c = e.Client.RvBufer[k + 1]; if (b == 0x5a && c == 0x01) { lbyte.Add(0x5b); } else if (b == 0x5a && c == 0x02) { lbyte.Add(0x5a); } else if (b == 0x5e && c == 0x01) { lbyte.Add(0x5d); } else if (b == 0x5e && c == 0x02) { lbyte.Add(0x5e); } else { lbyte.Add(b); } } for (int i = 0; i < lbyte.Count; i++) { recivebuffer[i] = lbyte[i]; } string batch_id = null; string task_id = null; //解析消息头 MSGHEAD head = new MSGHEAD(); byte[] headbuffer = new byte[MsgHeadLength]; Array.Copy(recivebuffer, 1, headbuffer, 0, MsgHeadLength); head = Get_MSGHeader(headbuffer); // head = Get_MSGHeader(e.Client.Datagram.Substring(0, MsgHeadLength)); //消息体数据 int Meg_len = (int)head.Msg_Length - MsgTotalLen; byte[] buffer = new byte[Meg_len];// Array.Copy(recivebuffer, 15, buffer, 0, Meg_len); // for (int i = 0; i < head.Msg_Length; ++i) // { // byte t = recivebuffer[i]; // Console.Write("{0:X}", t);//这个就是主要,填充 // Console.Write(" "); // // } // Console.Write("?"); //接入码s UInt32 centercode = head.Msg_GNSSCenter; TastInfo Tinfo = new TastInfo(); byte[] MesBody = null; //空数据 byte[] nu = new byte[0]; //判定是不是注册 REGISTER Is_re = new REGISTER(); //根据不同消息进行处理 Session sendDataSession = svr.FindSession(e.Client.ClientSocket); ICloneable copySession = (ICloneable)sendDataSession; Session clientSession = (Session)copySession.Clone(); // Console.Write("*"+head.Msg_ID); switch (head.Msg_ID) { //中心站只发过一个空包,或者包括简单的配置要求,服务器端组帧。 //链路登陆请求消息 case 0x0001: Is_re = IsRegest(head, buffer); // object structType = Is_re; byte[] btArray = new byte[1]; btArray[0] = Is_re.result; //MesBody = BitConverter.GetBytes(Is_re.result); svr.SendMessage(e.Client, btArray, 0x0002, centercode); //登录应答 if (Is_re.result == 0) { foreach (DictionaryEntry de in svr._sessionTable) //ht为一个Hashtable实例 { if (de.Value.Equals(clientSession)) { clientSession.DeviceId = Is_re.nameId; SessionId id = clientSession.ID; svr._sessionTable.Remove(clientSession.ID); svr._sessionTable.Add(id, clientSession); break; } } //更新数据库状态 string sql = "UPDATE device SET Device_Status = 1,Sockets = '" + clientSession.ClientSocket.RemoteEndPoint + "' WHERE Device_ID = '" + clientSession.DeviceId + "'"; database.Open(); database.ExcuteNonQuery(sql); database.Close(); } else { //Session sendDataSession = svr.FindSession(e.Client.ClientSocket); //更新数据库状态 string sql = "UPDATE device SET Device_Status = 0 WHERE Device_ID = '" + clientSession.DeviceId + "'"; database.Open(); database.ExcuteNonQuery(sql); database.Close(); } break; //用于心跳监测 case 0x0003: svr.SendMessage(clientSession, nu, 0x0004, centercode); //开启视频 // Console.Write("|" + buffer[1]); break; //批量任务下发(中心站往终端) //TEST NUM 4 Unint32_t 结果个数 //TEST INFO 804 Octet_string 检测结果信息 case 0x0005: //获取任务个数 byte[] numbuffer = new byte[4]; // Array.Copy(recivebuffer, 14, numbuffer, 0, 4); //获取个数 // Array.Reverse(numbuffer); // UInt32 num = BitConverter.ToUInt32(numbuffer,0); //组帧 TASK_INFO taskinfo = new TASK_INFO(); object structT = taskinfo; MesBody = Tinfo.StructureToByteArrayEndian(structT); foreach (Session cliSession in svr._sessionTable.Values) { if (cliSession.DeviceId == deviceid) { svr.SendMessage(cliSession, nu, 0x0005, centercode); //开启视频 break; } } //发送 break; //检测结果上传消息 //检测结果上传(终端往中心站) case 0x0006: sendDataSession = svr.FindSession(e.Client.ClientSocket); deviceid = sendDataSession.DeviceId; UpLoad(buffer, deviceid.ToString()); break; //开启实时监控 case 07: //获取发过来的设备id,根据id找到socket deviceid = UInt32.Parse(System.Text.Encoding.UTF8.GetString(buffer)); //提取控制的deviceid foreach (Session cliSession in svr._sessionTable.Values) { if (cliSession.DeviceId == deviceid) { svr.SendMessage(cliSession, nu, 0x0007, centercode); //开启视频 break; } } break; //中心站往检测仪结束实时视频 case 08: deviceid = UInt32.Parse(System.Text.Encoding.UTF8.GetString(buffer)); //提取控制的deviceid foreach (Session cliSession in svr._sessionTable.Values) { if (cliSession.DeviceId == deviceid) { svr.SendMessage(cliSession, nu, 0x0008, centercode); //开启视频 break; } } break; case 09: //视频上传(检测仪主动请求,中心站返回消息) UInt32 res = 0; byte[] meg = BitConverter.GetBytes(res); Array.Reverse(meg); svr.SendMessage(e.Client, meg, 0x000a, centercode); //录制视频上传应答 svr.FileBegine = true; svr.IsPic = false; break; //证件上传请求 case 0x0000b: UInt32 resu = 0; byte[] megs = BitConverter.GetBytes(resu); Array.Reverse(megs); svr.SendMessage(e.Client, nu, 0x000c, centercode); //上传应答 svr.FileBegine = true; svr.IsPic = true; foreach (Session cliSession in svr._sessionTable.Values) { if (cliSession.ClientSocket == e.Client.ClientSocket) { svr.device_id = cliSession.DeviceId.ToString(); } } break; //视频调阅请求 case 0x0000d: byte[] dev = new byte[12]; deviceid = UInt32.Parse(System.Text.Encoding.UTF8.GetString(buffer, 0, 4)); //提取控制的deviceid batch_id = System.Text.Encoding.UTF8.GetString(buffer, 4, 8); //提取控制的deviceid task_id = System.Text.Encoding.UTF8.GetString(buffer, 12, 4); //提取控制的deviceid Array.Copy(buffer, 4, dev, 0, 12); foreach (Session cliSession in svr._sessionTable.Values) { if (cliSession.DeviceId == deviceid) { svr.SendMessage(cliSession, nu, 0x0008, centercode); //开启视频 break; } } break; //视频调阅 case 0x000e: //将文件存储路径插入数据库 string filepath = System.Text.Encoding.UTF8.GetString(buffer, 0, GetLen(buffer)).Trim(); //更新数据库状态 string sql2 = "UPDATE detectioninfo SET video_path = '" + filepath + "' WHERE batch_id = '" + batch_id + "' AND task_id = '" + task_id + "'"; database.Open(); database.ExcuteNonQuery(sql2); database.Close(); break; //工作参数 case 0x0000f: break; //状态和工作参数 case 0x0010: break; //参数配置 case 0x0011: byte[] aa = new byte[4]; Array.Copy(buffer, 0, aa, 0, 4); byte[] Msg = new byte[buffer.Length - 4]; Array.Copy(buffer, 4, Msg, 0, buffer.Length - 4); deviceid = UInt32.Parse(System.Text.Encoding.UTF8.GetString(aa)); //提取控制的deviceid foreach (Session cliSession in svr._sessionTable.Values) { if (cliSession.DeviceId == deviceid) { svr.SendMessage(cliSession, Msg, 0x0012, centercode); //开启视频 break; } } break; //数据管理 case 0x0012: break; //设备管理消息 case 0x0013: break; //远程版本升级 case 0x0014: break; //版本升级应答 case 0x0015: break; //通用消息 case 0xf000: break; default: break; } }
/// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void RecvData(object sender, NetEventArgs e) { // string info = string.Format("recv data:{0} from:{1}.", e.Client.Datagram, e.Client); TcpSvr svr = (TcpSvr)sender; byte[] recivebuffer = System.Text.Encoding.UTF8.GetBytes(e.Client.Datagram); byte[] buffer = new byte[MsgHeadLength]; Array.Copy(recivebuffer, 1, buffer, 0, MsgHeadLength); TastInfo Info = new TastInfo(); MSGHEAD head = new MSGHEAD(); object headType = head; Info.ByteArrayToStructureEndian(buffer, ref headType, 0); head = (MSGHEAD)headType; string centercode = head.Msg_GNSSCenter.ToString(); switch (head.Msg_ID) { //用于心跳监测 case 03: svr.SendMessage(e.Client, "", 0x0004, centercode); // svr.SendMessage(e.Client, "", 0x0003, centercode); break; //检测结果上传消息 //TEST NUM 4 Unint32_t 结果个数 //TEST INFO 804 Octet_string 检测结果信息 case 06: byte[] test_num = new byte[4]; Array.Copy(recivebuffer, MsgHeadLength + 1, test_num, 0, 4); Array.Reverse(test_num); UInt32 num = (UInt32)BitConverter.ToInt32(test_num, 0); byte[] buffer3 = new byte[head.Msg_Length - 18 - 4]; Array.Copy(recivebuffer, MsgHeadLength + 1 + 4, buffer3, 0, head.Msg_Length - 18 - 4); DETECTION_INFO detInfo = new DETECTION_INFO(); object detInfoType = detInfo; Info.ByteArrayToStructureEndian(buffer3, ref detInfoType, 0); detInfo = (DETECTION_INFO)detInfoType; // DataTable tbInfo = LoadDetectionInfo(); // DataSet ds = new DataSet(); // // DataRow r = tbInfo.NewRow(); // r["p_name"] = System.Text.Encoding.UTF8.GetString(detInfo.p_name, 0, GetLen(detInfo.p_name)).Trim(); // r["sample_name"] = System.Text.Encoding.UTF8.GetString(detInfo.sample_name,0,GetLen(detInfo.sample_name)).Trim(); // r["channel"] = detInfo.channel; // r["type"] = System.Text.Encoding.UTF8.GetString(detInfo.type, 0, GetLen(detInfo.type)); // r["standard"] = System.Text.Encoding.UTF8.GetString(detInfo.standard, 0, GetLen(detInfo.standard)); // r["sample_no"] = System.Text.Encoding.UTF8.GetString(detInfo.sample_no, 0, GetLen(detInfo.sample_no)).Trim(); // r["sites"] = System.Text.Encoding.UTF8.GetString(detInfo.sites, 0, GetLen(detInfo.sites)).Trim(); // r["submission_unit"] = System.Text.Encoding.UTF8.GetString(detInfo.submission_unit, 0, GetLen(detInfo.submission_unit)); // r["test_operator"] = System.Text.Encoding.UTF8.GetString(detInfo.test_operator, 0, GetLen(detInfo.test_operator)); // // r["test_unit"] = System.Text.Encoding.UTF8.GetString(detInfo.test_unit, 0, GetLen(detInfo.test_unit)); // r["test_time"] = System.Text.Encoding.UTF8.GetString(detInfo.test_time, 0, GetLen(detInfo.test_time)); // // r["User_Id"] = e.Client.UserId; // // //并将数据写入到数据库 // tbInfo.Rows.Add(r); string p_name = System.Text.Encoding.UTF8.GetString(detInfo.p_name, 0, GetLen(detInfo.p_name)).Trim(); string sample_name = System.Text.Encoding.UTF8.GetString(detInfo.sample_name, 0, GetLen(detInfo.sample_name)).Trim(); int channel = (int)detInfo.channel; string type = System.Text.Encoding.UTF8.GetString(detInfo.type, 0, GetLen(detInfo.type)); string standard = System.Text.Encoding.UTF8.GetString(detInfo.standard, 0, GetLen(detInfo.standard)); string sample_no = System.Text.Encoding.UTF8.GetString(detInfo.sample_no, 0, GetLen(detInfo.sample_no)).Trim(); string sites = System.Text.Encoding.UTF8.GetString(detInfo.sites, 0, GetLen(detInfo.sites)).Trim(); string submission_unit = System.Text.Encoding.UTF8.GetString(detInfo.submission_unit, 0, GetLen(detInfo.submission_unit)); string test_operator = System.Text.Encoding.UTF8.GetString(detInfo.test_operator, 0, GetLen(detInfo.test_operator)); string test_unit = System.Text.Encoding.UTF8.GetString(detInfo.test_unit, 0, GetLen(detInfo.test_unit)); string test_time = System.Text.Encoding.UTF8.GetString(detInfo.test_time, 0, GetLen(detInfo.test_time)); DateTime dt = DateTime.ParseExact(test_time, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); int User_Id = (int)e.Client.UserId; string strsql = "Insert Into " + "detectioninfo(p_name,sample_name,channel,type,standard,sample_no,sites,submission_unit,test_operator,test_unit,test_time,User_Id)" + "values('" + p_name + "','" + sample_name + "'," + channel + ",'" + type + "','" + standard + "','" + sample_no + "','" + sites + "','" + submission_unit + "','" + test_operator + "','" + test_unit + "','" + test_time + "'," + User_Id + ")"; dbMySql.Open(databaseName); dbMySql.ExcuteNonQuery(databaseName, strsql); dbMySql.Close(databaseName); break; case 09: //视频上传 svr.SendMessage(e.Client, 0, 0x000a, centercode); break; case 0x000e: //远程状态和工作参数查询应答消息 //具体参数不明确 break; default: break; } //测试把收到的数据返回给客户端 //svr.SendText(e.Client, e.Client.Datagram); //MessageBox.Show(message.ToString()); //svr.SendFile(this.textBox1.Text); }