'System.Net.Sockets.TcpListener.TcpListener(int) is obsolete

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Darwin

    'System.Net.Sockets.TcpListener.TcpListener(int) is obsolete

    Setting a server to listen on 8080 for incoming connections. Written in
    VS2005 on a Multi-homed machine.
    I get the warning:
    Warning 1 'System.Net.Soc kets.TcpListene r.TcpListener(i nt)' is obsolete:
    'This method has been deprecated. Please use TcpListener(IPA ddress
    localaddr, int port) instead.
    on the code:
    TcpListener tcpListener = new TcpListener(808 0);

    Do I really have to specify every IP address that I want to listen on?

    The program compiled by changing the code to:

    Int32 port = 8080;

    IPAddress localAddr = IPAddress.Parse ("127.0.0.1" );

    TcpListener tcpListener = new TcpListener(loc alAddr, port);

    But does it mean that I am only listening on 127.0.0.1:8080? Why do I have
    to specify an IP address I thought that specifying a port automatically
    meant that you would be listening on that port for all IP addresses?

    Just want to understand why


  • Jeroen Mostert

    #2
    Re: 'System.Net.Soc kets.TcpListene r.TcpListener(i nt) is obsolete

    Darwin wrote:
    Setting a server to listen on 8080 for incoming connections. Written in
    VS2005 on a Multi-homed machine.
    I get the warning:
    Warning 1 'System.Net.Soc kets.TcpListene r.TcpListener(i nt)' is obsolete:
    'This method has been deprecated. Please use TcpListener(IPA ddress
    localaddr, int port) instead.
    on the code:
    TcpListener tcpListener = new TcpListener(808 0);
    >
    Do I really have to specify every IP address that I want to listen on?
    >
    No. Use IpAddress.Any to listen on all local addresses.
    The program compiled by changing the code to:
    >
    Int32 port = 8080;
    >
    IPAddress localAddr = IPAddress.Parse ("127.0.0.1" );
    >
    This is clumsy; IPAddress.Loopb ack is a constant field for this. And yes,
    this only listens on 127.0.0.1, so external hosts can't reach it.

    --
    J.

    Comment

    Working...