Thursday, February 12, 2015

How to check TcpListener is listening?

In TcpListener class, there is a property called Active but it a proctected one.
https://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.active(v=vs.110).aspx

Solution:
Create a sub class from TcpListener, and expose this property by yourself.

Code example:
    public class Listener : TcpListener
    {
        public Listener(int portNumber): base(IPAddress.Any, portNumber) {}
        public bool IsAcitve
        {
            get { return this.Active; }
        }
    }