Bug 275 - Net.Tcp doesn't listen on 0.0.0.0 or ::0
Summary: Net.Tcp doesn't listen on 0.0.0.0 or ::0
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies ()
Version: master
Hardware: PC Linux
: Normal major
Target Milestone: Untriaged
Assignee: Martin Baulig
URL:
Depends on:
Blocks:
 
Reported: 2011-08-12 02:59 UTC by Stephen Kou
Modified: 2012-09-05 16:46 UTC (History)
4 users (show)

Tags: net.tcp listen address, WCF
Is this bug a regression?: ---
Last known good build:


Attachments
Test case that repros issue (537 bytes, text/plain)
2011-08-13 06:03 UTC, Stephen Kou
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Stephen Kou 2011-08-12 02:59:04 UTC
On Microsoft's .NET, specifying an address of net.tcp://localhost:<port>/<path> causes WCF to listen on all addresses (0.0.0.0).  Specifying net.tcp://127.0.0.1:<port>/<path> forces it to listen on localhost only.  

I couldn't find a way to get Mono's WCF to listen on all addresses: "localhost" causes it to listen on 127.0.0.1, and "0.0.0.0" throws an exception from Dns.GetHostEntry.

Perhaps in NetTcpListener.cs check to see if the hostname is 'localhost', then force it to be IPAddress.Any in the TcpListener creation?
Comment 1 Miguel de Icaza [MSFT] 2011-08-12 17:12:01 UTC
Again, a self-contained simple test case would get the effort moving a lot faster.
Comment 2 Stephen Kou 2011-08-13 06:03:20 UTC
Created attachment 119 [details]
Test case that repros issue

The following code listens on 0.0.0.0 on ms.net/windows, but only on 127.0.0.1 on mono/linux.
Comment 3 John Hargrove 2011-09-19 21:51:54 UTC
I had this issue as well. A workaround in the near-term is to use the computer's hostname. For example:

string uri = string.Format("net.tcp://{0}:5000/MyService", Dns.GetHostName());

This works for me. But yes, it should most certainly listen on IPAddress.Any (aka 0.0.0.0), see http://msdn.microsoft.com/en-us/library/system.net.ipaddress.any.aspx
Comment 4 Martin Baulig 2012-09-05 16:46:30 UTC
Fixed; mono master commit c99bb5c.