Ejemplo n.º 1
0
        /// <summary>
        /// Spawn a thread that listens to incoming connections
        /// </summary>
        public void Start(OnNewClient onConnection, Action<Socket> beforeBindListeningSocket)
        {
            InitListenException = null;
            InitListenFinished.Reset();
            IsListening = false;
            IsShuttingDown = false;
            OnClientStart = onConnection;
            BeforeBindListeningSocket = beforeBindListeningSocket;

            ListeningThread = new Thread(StartThread);
            ListeningThread.Name = "ListenTCP";
            ListeningThread.IsBackground = true;
            ListeningThread.Start();

            const int cleanTimeout = 300 * 1000; // in ms
            CleanTimer = new Timer(new TimerCallback(CheckSockets), null,
                cleanTimeout, cleanTimeout);
        }
Ejemplo n.º 2
0
        public IPEndPoint Start()
        {
            ListeningSocket     = null;
            InitListenException = null;
            InitListenFinished.Reset();
            IsListening    = false;
            IsShuttingDown = false;

            listeningThread = new Thread(StartThread)
            {
                Name         = "ListenTCP",
                IsBackground = true
            };
            listeningThread.Start();

            const int cleanTimeout = 300 * 1000; // in ms

            cleanTimer = new Timer(CheckSockets, null, cleanTimeout, cleanTimeout);

            InitListenFinished.WaitOne();
            EndPoint = (IPEndPoint)ListeningSocket.LocalEndPoint;
            return(EndPoint);
        }