Beispiel #1
0
        public void StartServer()
        {
            var name = Dns.GetHostName();
            var ipV6 = Dns.GetHostEntry(name).AddressList.ToList().Find((p) => (p.AddressFamily == AddressFamily.InterNetworkV6));
            var ip   = Dns.GetHostEntry(name).AddressList.ToList().Find((p) => (p.AddressFamily == AddressFamily.InterNetwork));

            GameWindow.GameMessages[0] = ip.ToString();
            var forceip = IPAddress.Parse("10.0.0.120");

            listener = new TcpListener(ip, Port);
            listener.Start();
            Console.WriteLine("Starting Server IP:" + ip + " Port:" + Port);
            Console.WriteLine("Waiting for clients...");

            while (true)
            {
                while (!listener.Pending())
                {
                    Console.WriteLine("Listener Sleeping...");
                    Thread.Sleep(5000);
                }
                Console.WriteLine("Listener Wake up! connecting client");
                ConnectClients newConnection = new ConnectClients();
                newConnection.listener = this.listener;
                ConnectNewClient       = new Thread(new ThreadStart(newConnection.AcceptConnection));
                ConnectionThreads.Add(ConnectNewClient);
                ConnectNewClient.Start();
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            IModel         model      = new MainModel();
            IMainView      view       = new ConnectClients();
            IMainPresentor controller = new MainPresentor(new ConvertJsonFormat(), view, model);

            controller.Start();
        }
 public void ShutdownCallback(ConnectionHandler caller)
 {
     lock (ShutdownLocker)
     {
         if (DoneBool)
         {
             return;
         }
         EndOfDictionary = true;
         ConnectClients.Remove(caller);
         if (ConnectClients.Count == 0)
         {
             DoneBool = true;
         }
     }
 }
Beispiel #4
0
 public void AcceptClients()
 {
     while (true)
     {
         var client = MasterServer.AcceptTcpClient();
         if (client.Connected)
         {
             Task.Factory.StartNew(() =>
             {
                 var ch = new ConnectionHandler(client, this);
                 ch.HandleConnection();
             });
             ConnectClients.Add(client);
             Console.WriteLine("Client added and is now awaiting work: " + client.GetHashCode());
         }
     }
 }
 private void AcceptClients()
 {
     while (!IsDone())
     {
         try
         {
             var client = MasterServer.AcceptTcpClient();
             if (client.Connected)
             {
                 var ch = new ConnectionHandler(client, this);
                 Task.Factory.StartNew(() =>
                 {
                     ch.HandleConnection();
                 });
                 ConnectClients.Add(ch);
                 Console.WriteLine("Client added and is now awaiting work: " + client.GetHashCode());
             }
         }
         catch (Exception)
         {
             Console.WriteLine("Reached the end of dictionary");
         }
     }
 }