Exemplo n.º 1
0
        static void Main(string[] args)
        {
            /*Command reg = new Registration();
             *
             * Communicate request = new Communicate { user = new User { username = "******", password = "******", age = 23 } };
             *
             * reg.execute(request);
             * Communicate response = reg.Response;
             *
             * Console.WriteLine("Status: " + reg.Status);
             * Console.WriteLine(response.message.content);
             *
             * return;*/

            try
            {
                Int32     port  = 13000;
                IPAddress local = IPAddress.Parse("127.0.0.1");

                server = new TcpListener(local, port);

                server.Start();
                Console.WriteLine("Oczekiwanie na nadchodzące połączenia...");
                Console.WriteLine("");
                while (true)
                {
                    ConnectionThread t       = new ConnectionThread(server.AcceptTcpClient());
                    Thread           oThread = new Thread(new ThreadStart(t.connectionHandling));

                    oThread.Start();
                    oThread.Join();
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("Błąd gniazda: {0}", e);
            }
            catch (Exception e)
            {
                Console.WriteLine("Błąd", e);
            }
            finally
            {
                server.Stop();
            }
        }
Exemplo n.º 2
0
        public void StartServer()
        {
            byte[]      adr     = { 127, 0, 0, 1 };
            IPAddress   ipAdr   = new IPAddress(adr);
            TcpListener newsock = new TcpListener(ipAdr, 12345);

            newsock.Start();
            while (true)
            {
                StatusTextBox.AppendText("Waiting for a client...");
                TcpClient client = newsock.AcceptTcpClient();
                connections.Add(client);
                StatusTextBox.AppendText("Client connected");
                Thread t0 = new Thread(() => ConnectionThread.RunT0(client, connections));
                t0.Start();
            }
        }