Example #1
0
        public void ConstructorTest_Zero()
        {
            ushort port = 0;
            WebServer ws = new WebServer(port);

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

            var result = ws.Start();
            Assert.AreEqual("Started...",result);
        }
Example #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);
        }
Example #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();
     //}
 }
Example #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();
            //}
            
        }
Example #7
0
 static void Main(string[] args)
 {
     WebServer ws = new WebServer();
     ws.Start();
 }
Example #8
0
        static void Main(string[] args)
        {
            WebServer ws = new WebServer();

            ws.Start();
        }