Exemple #1
0
        static void Main(String[] args)
        {
            int TPort = 0;

            while (TPort == 0)
            {
                Console.WriteLine("Enter port number:");
                string portString = Console.ReadLine();

                Int32.TryParse(portString, out TPort);
                if (TPort == 0)
                {
                    Console.WriteLine(portString == "0" ? "Port cant be 0." : "Bad port, not a number.");
                }
            }
            Console.WriteLine();
            Console.WriteLine("Enter Document Root path (to change it - restart application):");
            FileHandlercs.SetDir(Console.ReadLine());

            Console.WriteLine("");
            Console.WriteLine("Starting server...");

            l = new Listener(TPort);
            l.SocketAcceptedE_Handler += new EventHandler <SocketAcceptedEventHandler>(SocketAccepted);
            l.Start();
            sockets = new List <Socket>();

            Console.ReadLine();
            l.EndListener();
        }
Exemple #2
0
        private void callback(IAsyncResult ar)
        {
            try
            {
                Socket CS = MainSocket.EndAccept(ar);

                if (SocketAcceptedE_Handler != null)
                {
                    SocketAcceptedE_Handler(this, new SocketAcceptedEventHandler(CS));
                    Send(CS, FileHandlercs.GetResponseMessage());
                }

                MainSocket.BeginAccept(callback, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }