Ejemplo n.º 1
0
            private void Run()
            {
                UInt32 acceptCount = 0;

                this.listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                listenSocket.Bind(new IPEndPoint(IPAddress.Any, listenPort));
                listenSocket.Listen(server.socketBackLog);

                try
                {
                    while (keepRunning)
                    {
                        MessageLogger nextLogger = new ConsoleMessageLogger(String.Format("Port {0} Handler {1}", listenPort, acceptCount.ToString()));

                        nextLogger.Log("Listening");
                        Socket newClientSocket = listenSocket.Accept();

                        nextLogger.Log("Accepted {0}", newClientSocket.RemoteEndPoint);
                        server.NewClient(new IncomingConnection(newClientSocket, listenPort));

                        acceptCount++;
                    }
                }
                catch (SocketException se)
                {
                    if (keepRunning)
                    {
                        throw se;
                    }
                }
            }
Ejemplo n.º 2
0
        private void Run()
        {
            Console.WriteLine("Starting Proxy Server {0}", this);

            UInt32 acceptCount = 0;

            this.listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            listenSocket.Bind(new IPEndPoint(IPAddress.Any, listenPort));
            listenSocket.Listen(socketBackLog);

            while (keepRunning)
            {
                try
                {
                    MessageLogger nextLogger = new ConsoleMessageLogger(String.Format("Handler {0}", acceptCount.ToString()));

                    nextLogger.Log("Listening");
                    Socket newClientSocket = listenSocket.Accept();

                    nextLogger.Log("Accepted {0}", newClientSocket.RemoteEndPoint);

                    ProxyHandler proxyHandler = new ProxyHandler(nextLogger, new NetworkStream(newClientSocket));

                    Thread handlerThread = new Thread(new ThreadStart(proxyHandler.Run));
                    handlerThread.Name = String.Format("{0} Thread", nextLogger.name);
                    handlerThread.Start();

                    acceptCount++;
                }
                catch (SocketException se)
                {
                    if (keepRunning)
                    {
                        throw se;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Run()
        {
            Console.WriteLine("Starting FTP Server {0}", this);

            UInt32 acceptCount = 0;

            Socket listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            listenSocket.Bind(new IPEndPoint(IPAddress.Any, listenPort));
            listenSocket.Listen(socketBackLog);

            while (true)
            {
                MessageLogger nextMessageLogger = new ConsoleMessageLogger(String.Format("Handler {0}", acceptCount.ToString()));

                nextMessageLogger.Log("Listening");
                Socket newClientSocket = listenSocket.Accept();

                nextMessageLogger.Log("Accepted {0}", newClientSocket.RemoteEndPoint);


                FtpHandler ftpHandler = new FtpHandler(
                    new DictionaryCommandHandler((IPEndPoint)newClientSocket.LocalEndPoint, rootPath),
                    new NetworkStream(newClientSocket),
                    nextMessageLogger,
                    new ConsoleDataLoggerWithLabels(String.Format("[{0} Data]:", nextMessageLogger.name),
                                                    String.Format("[{0} End of Data]", nextMessageLogger.name)));

                Thread handlerThread = new Thread(new ThreadStart(ftpHandler.Run));
                handlerThread.IsBackground = true;
                handlerThread.Name         = String.Format("{0} Thread", nextMessageLogger.name);
                handlerThread.Start();

                acceptCount++;
            }
        }