Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Darwin - 23 Mar 2008 11:53 GMT
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.Sockets.TcpListener.TcpListener(int)' is obsolete:
'This method has been deprecated. Please use TcpListener(IPAddress
localaddr, int port) instead.
on the code:
TcpListener tcpListener = new TcpListener(8080);

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(localAddr, 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 - 23 Mar 2008 12:06 GMT
> Setting a server to listen on 8080 for incoming connections. Written in
> VS2005 on a Multi-homed machine.
[quoted text clipped - 6 lines]
>
> 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.Loopback is a constant field for this. And yes,
this only listens on 127.0.0.1, so external hosts can't reach it.

Signature

J.

Gilles Kohl [MVP] - 23 Mar 2008 12:24 GMT
>Setting a server to listen on 8080 for incoming connections. Written in
>VS2005 on a Multi-homed machine.
[quoted text clipped - 18 lines]
>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?

Hmm, quoting from the docs:

"If you do not care which local address is assigned, specify IPAddress.Any for
the localaddr parameter, and the underlying service provider will assign the
most appropriate network address. This might help simplify your application if
you have multiple network interfaces."

I found an interesting discussion about the potential rationale for the
deprecation here:

http://channel9.msdn.com/ShowPost.aspx?PostID=28931

  Regards,
  Gilles.
Darwin - 23 Mar 2008 19:19 GMT
I appreciate the response, when I look in the docs, there are 3 overloaded
constructor methods for tcpListener and it doesn't mention deprecation.
Anyway, I am back on track now.
Thanks
> Hmm, quoting from the docs:
>
[quoted text clipped - 13 lines]
>   Regards,
>   Gilles.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.