Ejemplo n.º 1
0
        private (bool sucessfulInitiaition, double similarityThreshold, int miniBatchSize, string fileLocation) ServerInitiation(Socket inHandler)
        {
            string _fileLocation         = null;
            var    _initiationSuccessful = false;
            double _similarityThreshold  = 0.0;
            int    _miniBatchSize        = 0;

            // Handshake Loop - Abort if loop fails 10 times
            for (var i = 0; i < 10; i++)
            {
                // Receive filename from server
                var _fileName = NT.ReceiveString(inHandler);
                // Echo video filename to server
                NT.SendString(inHandler, _fileName);

                // Receive file location from server
                _fileLocation = NT.ReceiveString(inHandler);
                // Echo file location
                NT.SendString(inHandler, _fileLocation);

                // Receive similarity threshold from server
                _similarityThreshold = NT.ReceiveDouble(inHandler);
                // Echo similarity threshold
                NT.SendDouble(inHandler, _similarityThreshold);

                // Receive mini batch size from server
                _miniBatchSize = NT.ReceiveInt(inHandler);
                // Echo mini batch size
                NT.SendInt(inHandler, _miniBatchSize);

                // Send file checksum to ensure both machines are referring to same file
                NT.SendString(inHandler, "file checksum test");

                // Receive "file good" confirmation from server
                var response = NT.ReceiveString(inHandler);
                if (response == "OK")
                {
                    // Send machine name to server
                    NT.SendString(inHandler, "client_name");

                    _initiationSuccessful = true;
                    break;
                }
            }

            // Proceed to connection handler stage 2
            return(_initiationSuccessful, _similarityThreshold, _miniBatchSize, _fileLocation);
        }
Ejemplo n.º 2
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);
        }