Exemple #1
0
        private void SendPacket(byte[] bytes, int size, EndPoint endPoint, int ID, int position, int count)
        {
            byte[] tmpArray = new byte[size];
            Array.Copy(bytes, 0, tmpArray, 0, size);
            List <byte[]> list = packetUtil.InfoToPacket(tmpArray, ID, position, count);

            SendList(list, endPoint);
        }
Exemple #2
0
        //发送二进制数据
        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);
        }