Example #1
0
        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;
        }
Example #2
0
        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++;
                }
            }
        }
Example #3
0
        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);
            }
        }
Example #4
0
        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);
        }
Example #5
0
 public static void CloseServer()
 {
     Send(ServiceObjectConvert.协议编码(0xff, curGUID.ToByteArray()));
 }
Example #6
0
 public static void 文件下载超时()
 {
     byte[] sendData = ServiceObjectConvert.协议编码((byte)TransmiteEnum.载文件, null);
     Client.Send(sendData);
 }
Example #7
0
 public static void 启动远程强制退分检测(string ICCardID)
 {
     byte[] sendData = ServiceObjectConvert.协议编码((byte)TransmiteEnum.启动远程强制退分检测, Encoding.GetEncoding("gb2312").GetBytes(ICCardID));
     Client.Send(sendData);
 }
Example #8
0
 public static void 获取本店密码()
 {
     byte[] sendData = ServiceObjectConvert.协议编码((byte)TransmiteEnum.获取店密码, null);
     Client.Send(sendData);
 }
Example #9
0
 public static void  载文件(string fileName)
 {
     byte[] sendData = ServiceObjectConvert.协议编码((byte)TransmiteEnum.载文件, Encoding.GetEncoding("gb2312").GetBytes(fileName));
     Client.Send(sendData);
 }