Пример #1
0
        private void send(int i, ref int dataGramCount)
        {
            //get the ack (read the ack number)
            int receivedAck;

            do {

                //set state for sending
                this.clientState.send();

                //send packet
                this.startPacket();
                this.sendDataBlock(i);
                this.commit();

                receivedAck = retrSendAck(i);
                //send the next packet

                i = receivedAck + 1;

            }
            while (receivedAck > 0 && receivedAck < dataGramCount);

            if (receivedAck == dataGramCount)
            {
                Console.WriteLine("Packages sent successfully");
                this.context.protocolMSGInv("File \"" + Path.GetFileName(filename) + "\" has been sent!");
                //go back to init state
                this.clientState = new InitState();
                sendingFileStream.Close();
                sendingFileStream = null;
            }
            else if (receivedAck == -1)
            {
                Console.WriteLine("Error! Client reset!");
                resetClient();
            }
            else if (receivedAck > dataGramCount)
            {
                Console.WriteLine("Strange error");
            }
        }
Пример #2
0
 private void resetClient()
 {
     //reset client
     udpClient.Close();
     udpClient = null;
     this.clientState = new InitState();
 }
Пример #3
0
 private Client()
 {
     //The first time we have to generate a state on our own and not by the state mechanism
     //Then we go into the init-Method according to the state
     clientState = new InitState();
 }
Пример #4
0
 //Setter and getter for ClientState
 public void setClientState(ClientState state)
 {
     this.clientState = state;
 }