[Mono-list] Listen on same port ipv4 and ipv6

J Decker d3ck0r at gmail.com
Fri Dec 11 21:56:05 UTC 2015


On Fri, Dec 11, 2015 at 1:50 PM, J Decker <d3ck0r at gmail.com> wrote:
> (First let me vent a little and say I LOVE all the consistency in
> network libraries; in MS.NET closing a IPV6 TcpClient sets Client to
> null, whereas IPV4 TcpCLient only disposes the object)
>
> I found this old message with no responses..
>
> http://lists.ximian.com/pipermail/mono-list/2014-May/050905.html
>
> I want to listen at the same port address at 0.0.0.0 and :: (ipv4 and
> 6 address respectively)
>
> in C I would open two listeners.  But I think maybe the .NET runtime
> is pre-checking if that port is already used in some internal list of
> sockets before attemping to open it in reality.
>
> in C# I will have to do the same thing, since connecting to the v6
> address with only the v4 listener at 0.0.0.0 listening fails to
> connect and times out.
>
> On Windows I have to, and it works; but again with Mono on Linux it
> doesn't work.

This is the code that fails.

internal GameServer()
{
byte[] raw_ipv4 = { 0, 0, 0, 0 };
IPAddress addr = new IPAddress( raw_ipv4 );
listener = new TcpListener( addr, Settings.Read( "Server Port",
GameServer.serving_port ) );
listener.Start();
byte[] raw_ipv6 = { 0,0,0,0
,0, 0, 0, 0
,0, 0, 0, 0
,0, 0, 0, 0 };
IPAddress addr_v6 = new IPAddress( raw_ipv6 );
listener_v6 = new TcpListener( addr_v6, Settings.Read( "Server Port",
GameServer.serving_port ) );
listener_v6.Start(); /* Exception - EADDRINUSE ; even though it's not
and needs to be opened */
}


More information about the Mono-list mailing list