Exemplo n.º 1
0
        public void ConstructorTest_Zero()
        {
            ushort port = 0;
            WebServer ws = new WebServer(port);

            Assert.AreEqual(port, ws.Port);
        }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     ushort port = 8081;
     WebServer ws = new WebServer(port);
     ws.Start();
     ws.Start();
 }
Exemplo n.º 3
0
        public void StartTest_FirstCall()
        {
            ushort port = 0;
            WebServer ws = new WebServer(port);

            var result = ws.Start();
            Assert.AreEqual("Started...",result);
        }
Exemplo n.º 4
0
        public void StartTest_SecondCall()
        {
            ushort port = 0;
            WebServer ws = new WebServer(port);

            ws.Start();
            var result = ws.Start();
            Assert.AreEqual("Already started!", result);
        }
Exemplo n.º 5
0
 static void Main(string[] args)
 {
     ushort port = 8081;
     WebServer ws = new WebServer(port);
     ws.Start();
     //while (true)
     //{
     //    var command = Console.ReadLine();
     //    if (command == "exit")
     //        ws.Stop();
     //}
 }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            ushort port = 8081;
            if (args.Length != 0)
            {
                ushort paramPort;
                if (UInt16.TryParse(args[0], out paramPort))
                {
                    port = paramPort;
                }
            }
            else
            {
                string confPort = System.Configuration.ConfigurationManager.AppSettings["port"];
                if (confPort != null)
                {
                    UInt16.TryParse(confPort, out port);
                }
                else
                {
                    Console.WriteLine("{0}", port);
                }
            }
            bool isAvailable = true;

            IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
            TcpConnectionInformation[] tcpConnArray = ipGlobalProperties.GetActiveTcpConnections();

            foreach (TcpConnectionInformation tcpi in tcpConnArray)
            {
                if (tcpi.LocalEndPoint.Port == port)
                {
                    isAvailable = false;
                    break;
                }
            }

            IPEndPoint[] listeningConnArray = ipGlobalProperties.GetActiveTcpListeners();
            foreach (IPEndPoint conn in listeningConnArray)
            {
                if (conn.Port == port)
                {
                    isAvailable = false;
                    break;
                }
            }

            if (isAvailable)
            {
                WebServer ws = new WebServer(port);
                ws.Start();
            }
            else
            {
                Console.WriteLine("Error! The requsted port is already in use.");
            }
            
            //while (true)
            //{
            //    var command = Console.ReadLine();
            //    if (command == "exit")
            //        ws.Stop();
            //}
            
        }
Exemplo n.º 7
0
 static void Main(string[] args)
 {
     WebServer ws = new WebServer();
     ws.Start();
 }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            WebServer ws = new WebServer();

            ws.Start();
        }