Esempio n. 1
0
        private string ClientInitiation(Socket inHandler, string inFileName, string inFileLocation, string inChecksum)
        {
            string clientName = null;

            // Handshake Loop - Abort if loop fails 10 times
            for (var i = 0; i < 10; i++)
            {
                var failureDetected = false;

                // Send video filename to client
                NT.SendString(inHandler, inFileName);
                // Receive filename echo from client
                var data = NT.ReceiveString(inHandler);
                // If client doesn't echo filename restart handshaking loop
                if (data != inFileName)
                {
                    failureDetected = true;
                }

                // Send video file location to client
                NT.SendString(inHandler, inFileLocation);
                // Receive file location echo from client
                data = NT.ReceiveString(inHandler);
                if (data != inFileLocation)
                {
                    failureDetected = true;
                }

                // Send similarity threshold to client
                NT.SendDouble(inHandler, _similarityThreshold);
                // Receive threshold echo from client
                var echoThreshold = NT.ReceiveDouble(inHandler);
                if (echoThreshold != _similarityThreshold)
                {
                    failureDetected = true;
                }

                // Send mini batch size to client
                NT.SendInt(inHandler, _miniBatchSize);
                // Receive batch size echo from client
                var echoBatchSize = NT.ReceiveInt(inHandler);
                if (echoBatchSize != _miniBatchSize)
                {
                    failureDetected = true;
                }

                // Receive checksum response from client
                data = NT.ReceiveString(inHandler);

                // If returned checksum matches what server has calculated
                if ((data == inChecksum) && failureDetected == false)
                {
                    // Send file good confirmation to client
                    NT.SendString(inHandler, "OK");

                    // Receive client name
                    data = NT.ReceiveString(inHandler);

                    // Proceed to connection handler stage 2
                    clientName = data;
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Client completed initiation handshake.");
                    Console.ResetColor();
                    break;
                }
                else
                {
                    // Send fail message to client
                    NT.SendString(inHandler, "FAIL");
                    continue;
                }
            }

            return(clientName);
        }