public void CheckProcess() { PacketUtil packetUtil = new PacketUtil(); foreach (var item in ReceivePool) { if (item.Value.leftTime < 0) { ReceivePool.Remove(item.Key); } // if (ResendBufferPool.ContainsKey(item.Key)) // ResendProcess(item.Value); if (item.Value.leftTime < 27000) { ResendProcess(item.Value); Console.WriteLine("lost processing"); /*foreach (var items in packetUtil.TotalCheck(item.Value.dic)) * { * Console.WriteLine(items.Value); * Console.WriteLine(items.Key); * }*/ } item.Value.leftTime -= 1000; } //发送整个重发缓冲池的数据 //SendInfo(ResendPool); }
//发送二进制数据 public void InfoSend(byte[] Info) { //首先调用工具类对数据进行分片,然后接受返回的list PacketUtil packetUtil = new PacketUtil(); List <byte[]> InfoList = packetUtil.InfoToPacket(Info); //先发送头部信息 //SendTag(InfoList[0], RemoteIPEndPoint); //获取大包ID放入发送缓冲池 int ID = packetUtil.GetID(InfoList[0]); DataPool dataPool = new DataPool(ID, new Dictionary <int, byte[]>(), (EndPoint)RemoteIPEndPoint); dataPool.AddList(InfoList); sendOutPool.Add(ID, dataPool); Console.WriteLine(dataPool.dic.Count); Socket temp = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); byte[] tempBytes = Encoding.UTF8.GetBytes("I will send file"); temp.SendTo(tempBytes, tempBytes.Length, SocketFlags.None, new IPEndPoint(RemoteIPEndPoint.Address, 8060)); bool check = true; /*while(check) * { * if (MsgBuffer.ContainsKey(RemoteIPEndPoint.Address.ToString())) * { * if (MsgBuffer[RemoteIPEndPoint.Address.ToString()].IndexOf("roger") >= 0) * { * check = false; * MsgBuffer.Remove(RemoteIPEndPoint.Address.ToString()); * } * } * else * { * Thread.Sleep(1000); * } * } * * Console.WriteLine("response received, starting transmission"); */ //发送数据 Send(dataPool, (EndPoint)RemoteIPEndPoint); }
private void processReByte(byte[] bytes, EndPoint endPoint) { PacketUtil packetUtil = new PacketUtil(); int id = packetUtil.GetID(bytes); int index = packetUtil.GetIndex(bytes); byte[] infoBytes = sendOutPool[id].dic[index]; Socket socket1 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //socket1.Bind(new IPEndPoint(hostIPEndPoint.Address, 8080)); socket1.SendTo(infoBytes, infoBytes.Length, SocketFlags.None, endPoint); //socket1.Dispose(); //Thread.Sleep(1); /*Console.WriteLine("已发送请求"); * Console.WriteLine(id); * Console.WriteLine(index);*/ }