コード例 #1
0
 public void sendFile(string filePath)
 {
     filePackets          = TCPCopycatPacketManager.FileToTCPCopycatPacket(@filePath);
     windowSize           = 10;
     windowLowerbound     = 25;
     windowHigherbound    = windowLowerbound + windowSize;
     sequenceNumberOffset = 25;
     sendFilePackets(filePackets);
 }
コード例 #2
0
        public void ClientSocketReceivedPacketCallback(TCPCopycatPacket packet, IPEndPoint sender)
        {
            Console.WriteLine("Received Packet numbered: " + packet.header.sequenceNumber.ToString());

            if (!packetReceived[GetClientSocketFromEndpoint(sender)].Contains(packet.header.sequenceNumber))
            {
                if (packet.header.FIN == 1)
                {
                    Console.WriteLine("Packet FIN received");
                }
                filePacketList[GetClientSocketFromEndpoint(sender)].Add(packet);
                packetReceived[GetClientSocketFromEndpoint(sender)].Add(packet.header.sequenceNumber);
            }

            packet.header.acknowledgeNumber = packet.header.sequenceNumber + 1;
            TCPCopyCatController.sendMessageToEndPoint(GetClientSocketFromEndpoint(sender), sender, packet);

            /*
             * if (packet.header.acknowledgeNumber == 30)
             * {
             *  Console.WriteLine("********** SENDING MULTIPLE TIME SAME PACKET *************");
             *  latency(250, 1251);
             *  TCPCopyCatController.sendMessageToEndPoint(GetClientSocketFromEndpoint(sender), sender, packet);
             *  latency(250, 1251);
             *  TCPCopyCatController.sendMessageToEndPoint(GetClientSocketFromEndpoint(sender), sender, packet);
             *  latency(250, 1251);
             *  TCPCopyCatController.sendMessageToEndPoint(GetClientSocketFromEndpoint(sender), sender, packet);
             * }*/
            /*
             * if (packet.header.acknowledgeNumber != 28)
             * {
             *  TCPCopyCatController.sendMessageToEndPoint(GetClientSocketFromEndpoint(sender), sender, packet);
             * }
             * if (packet.header.acknowledgeNumber == 31)
             * {
             *  Console.WriteLine("*** GoingTo send packet 30 ack ***");
             *  Thread.Sleep(10000);
             *  packet.header.acknowledgeNumber = 28;
             *  TCPCopyCatController.sendMessageToEndPoint(GetClientSocketFromEndpoint(sender), sender, packet);
             *  Console.WriteLine("*** SENT PACKET ***");
             * }
             */
            if (packet.header.FIN == 1)
            {
                filePacketList[GetClientSocketFromEndpoint(sender)].Sort(delegate(TCPCopycatPacket a, TCPCopycatPacket b)
                {
                    if (a.header.sequenceNumber < b.header.sequenceNumber)
                    {
                        return(-1);
                    }
                    return(1);
                });

                TCPCopycatPacketManager.TCPCopycatPacketArrayToFile(@"./" + sender.Port.ToString(), filePacketList[GetClientSocketFromEndpoint(sender)].ToArray());
            }
        }