static void CommandProcess() { while (true) { if (queueRecv.Count > 0) { try { UDPClientItemBusiness.ClientItem item = queueRecv.Dequeue(); List <byte> decodeData = new List <byte>(item.data); ServiceObjectConvert.转定义解码(ref decodeData); int len = BitConverter.ToUInt16(decodeData.ToArray(), 1); switch ((TransmiteEnum)decodeData[0]) { case TransmiteEnum.雷达注册授权响应: //心跳接收 ConnectRecvTime = DateTime.Now; break; default: break; } } catch (Exception ex) { Console.WriteLine(ex); } } else { Thread.Sleep(50); } } }
static void ConnectServer() { isRun = true; List <byte> dataBUF = new List <byte>(); dataBUF.Add((byte)curClientType); dataBUF.AddRange(curGUID.ToByteArray()); Send(ServiceObjectConvert.协议编码(0xf0, dataBUF.ToArray())); ConnectSendTime = DateTime.Now; }
public static void 文件(string fileName) { List <byte> data = new List <byte>(); if (fileName != "") { using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { curPacketCount = (UInt16)(fs.Length / PacketLength); curPacketRemain = (int)(fs.Length % PacketLength); if (curPacketRemain != 0) { curPacketCount++; } fs.Close(); } curPacketIndex = 0; data.AddRange(BitConverter.GetBytes(curPacketIndex)); data.AddRange(BitConverter.GetBytes(curPacketCount)); data.AddRange(Encoding.GetEncoding("gb2312").GetBytes(Path.GetFileName(fileName))); byte[] sendData = ServiceObjectConvert.协议编码((byte)TransmiteEnum.文件, data.ToArray()); Client.Send(sendData); curFileName = fileName; curPacketIndex++; } else { using (FileStream fs = new FileStream(curFileName, FileMode.Open, FileAccess.Read)) { byte[] dataRead; if (curPacketIndex > curPacketCount) { return; //发送完毕 } fs.Position = (curPacketIndex - 1) * PacketLength; if (curPacketIndex == curPacketCount) //最后一包数据 { dataRead = new byte[curPacketRemain]; fs.Read(dataRead, 0, curPacketRemain); } else { //正常包 dataRead = new byte[PacketLength]; fs.Read(dataRead, 0, PacketLength); } fs.Close(); data.AddRange(BitConverter.GetBytes(curPacketIndex)); data.AddRange(BitConverter.GetBytes(curPacketCount)); data.AddRange(dataRead); byte[] sendData = ServiceObjectConvert.协议编码((byte)TransmiteEnum.文件, data.ToArray()); Client.Send(sendData); curPacketIndex++; } } }
public static void SendCommand(string gID, TransmiteEnum cType, object data) { UDPClientItemBusiness.ClientItem curClient = new UDPClientItemBusiness.ClientItem(); var clients = clientList.Where(p => p.gID == gID); if (clients.Count() > 0) { curClient = clients.First(); byte[] dat = ServiceObjectConvert.SerializeObject(data); byte[] sendData = ServiceObjectConvert.协议编码((byte)cType, dat); Server.Send(((IPEndPoint)curClient.remotePoint).Address.ToString(), ((IPEndPoint)curClient.remotePoint).Port, sendData); } }
public static void Send(TransmiteEnum cType, object objData) { if (!isRun) { return; } IPEndPoint clients = new IPEndPoint(IPAddress.Parse(ServerIP), ServerPort); EndPoint epSender = (EndPoint)clients; byte[] data = null; if (objData != null) { data = ServiceObjectConvert.SerializeObject(objData); } byte[] sendData = ServiceObjectConvert.协议编码((byte)cType, data); client.BeginSendTo(sendData, 0, sendData.Length, SocketFlags.None, epSender, new AsyncCallback(SendCallBack), client); }
public static byte[] 协议编码(byte cmdType, byte[] data) { List <byte> dataBUF = new List <byte>(); if (data != null) { dataBUF.AddRange(data); } dataBUF.InsertRange(0, BitConverter.GetBytes((UInt16)dataBUF.Count)); dataBUF.Insert(0, cmdType); ServiceObjectConvert.转定义编码(ref dataBUF, 0x7D); ServiceObjectConvert.转定义编码(ref dataBUF, 0x7E); dataBUF.Insert(0, 0x7e); dataBUF.Add(0x7e); return(dataBUF.ToArray()); }
public static void CloseServer() { Send(ServiceObjectConvert.协议编码(0xff, curGUID.ToByteArray())); }
public static void 文件下载超时() { byte[] sendData = ServiceObjectConvert.协议编码((byte)TransmiteEnum.载文件, null); Client.Send(sendData); }
public static void 启动远程强制退分检测(string ICCardID) { byte[] sendData = ServiceObjectConvert.协议编码((byte)TransmiteEnum.启动远程强制退分检测, Encoding.GetEncoding("gb2312").GetBytes(ICCardID)); Client.Send(sendData); }
public static void 获取本店密码() { byte[] sendData = ServiceObjectConvert.协议编码((byte)TransmiteEnum.获取店密码, null); Client.Send(sendData); }
public static void 载文件(string fileName) { byte[] sendData = ServiceObjectConvert.协议编码((byte)TransmiteEnum.载文件, Encoding.GetEncoding("gb2312").GetBytes(fileName)); Client.Send(sendData); }