Exemplo n.º 1
0
        private void listenForClients()
        {
            tcpListener.Start();
            Console.WriteLine("The server is running at port 27015...");
            Console.WriteLine("The local End point is  :" +
                              tcpListener.LocalEndpoint);
            Console.WriteLine("Waiting for a connections....\n");
            while (true)
            {
                //blocks until a client has connected to the server
                TcpClient client = this.tcpListener.AcceptTcpClient();
                Console.WriteLine("\nConnection accepted from " + client.Client.LocalEndPoint);

                //client should send an integer specifying which kind of client it is
                byte[] cmd = new byte[4];
                client.Client.Receive(cmd, 0, 4, 0);
                int sampleType = BitConverter.ToInt32(cmd, 0);
                switch (sampleType)
                {
                case EPID_PROVISIONING_SAMPLE:
                {
                    Console.WriteLine("Connected client is EPID Provisioning Sample");
                    //create a thread to handle communication
                    //with connected client
                    EPIDProvisioningHandler ch = new EPIDProvisioningHandler();
                    Thread clientThread        = new Thread(new ParameterizedThreadStart(ch.handleClientComm));
                    clientThread.Start(client);
                }
                break;

                case EPID_SIGNING_SAMPLE:
                {
                    Console.WriteLine("Connected client is EPID Signing Sample");
                    //create a thread to handle communication
                    //with connected client
                    EPIDSigningHandler ch           = new EPIDSigningHandler();
                    Thread             clientThread = new Thread(new ParameterizedThreadStart(ch.handleClientComm));
                    clientThread.Start(client);
                }
                break;

                case SECURE_IMAGE:
                {
                    Console.WriteLine("Connected client is SECURE IMAGE");
                    //create a thread to handle communication
                    //with connected client
                    SecureImageHandler ch           = new SecureImageHandler();
                    Thread             clientThread = new Thread(new ParameterizedThreadStart(ch.handleClientComm));
                    clientThread.Start(client);
                }
                break;

                default: break;
                }
            }
        }
Exemplo n.º 2
0
        private void ListenForClients()
        {
            try
            {
                tcpListener.Start();
                Console.WriteLine("The server is running...");

                while (true)
                {
                    AcceptConnection();

                    // Client should send an integer specifying which sample it is
                    int sampleID = clientSocket.Client.ReceiveMessageAsInt();

                    SampleHandler sampleHandler = null;

                    switch (sampleID)
                    {
                    case EPID_PROVISIONING_SAMPLE:
                    {
                        Console.WriteLine("Connected client is EPID Provisioning Sample.");
                        sampleHandler = new EPIDProvisioningHandler();
                    }
                    break;

                    case EPID_SIGNING_SAMPLE:
                    {
                        Console.WriteLine("Connected client is EPID Signing Sample.");
                        sampleHandler = new EPIDSigningHandler();
                    }
                    break;

                    case SIGMA_SAMPLE:
                    {
                        Console.WriteLine("Connected client is SIGMA Sample.");
                        sampleHandler = new SIGMAHandler();
                    }
                    break;

                    default: break;
                    }

                    // Create a thread to handle communication with the connected client
                    if (sampleHandler != null)
                    {
                        Thread clientThread = new Thread(new ParameterizedThreadStart(sampleHandler.HandleClientCommunication));
                        clientThread.Start(clientSocket);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception was thrown. \nError message:");
                Console.WriteLine(e.Message);
            }
        }