コード例 #1
0
        static void Main()
        {
            int listenPort;

            // Prompt user to enter port (hard-code a port?? check assignment instructions)
            Console.WriteLine("Illuminati Confirmed");
            Console.Write("Enter Port: ");
            while (!Int32.TryParse(Console.ReadLine(), out listenPort))
            {
                Console.Write("Port Invalid.  Enter Port: ");
            }

            try
            {
                // Set up server
                TcpListener listenSocket = new TcpListener(IPAddress.Any, listenPort);
                listenSocket.Stop();
                listenSocket.Start();
                Console.WriteLine("\r\n::Server is active on the following address & port::");
                Console.WriteLine("Address: {0}:{1}", ((IPEndPoint)listenSocket.LocalEndpoint).Address,
                                  ((IPEndPoint)listenSocket.LocalEndpoint).Port);
                CentralIndex index = new CentralIndex();
                Console.WriteLine("\n---@ Peer Activity @---");

                // Listen for new Peer connections
                while (true)
                {
                    if (listenSocket.Pending())
                    {
                        TcpClient   newClient = listenSocket.AcceptTcpClient();
                        PeerManager pm        = new PeerManager(newClient, index);
                        pm.Start();
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("An error occured: {0}\r\n{1}", e.Message, e.StackTrace);
                Console.ReadLine();
            }
        }
コード例 #2
0
 // Constructor
 public PeerManager(TcpClient clientSocket, CentralIndex index)
 {
     _clientSocket = clientSocket;
     _index        = index;
 }
コード例 #3
0
 // Constructor
 public Request(TcpClient clientSocket, CentralIndex index, int id)
 {
     _clientSocket = clientSocket;
     _index        = index;
     _id           = id;
 }