Home Forums Support Cannot listen on certain connections

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2561
    Anonymous
    Inactive

    Hello,
    I have that specific problem, that my program cannot listen on any port. This only happens to certain users.
    I came to the point to write a test program which results in 10000 negative ports for some of those players.
    Here is the code:

                int positiv = 0;
                int negativ = 0;
    
                for (int i = 0; i < 10000; i++)
                {
                    Console.Write("Port {0}: ", i);
                    try
                    {
                        Connection.StartListening(ConnectionType.TCP, new IPEndPoint(IPAddress.Any, i));
                        Connection.StopListening();
                        Console.WriteLine("Positiv!");
                        positiv++;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Negativ!");
                        negativ++;
                    }
                }
    
                Console.WriteLine("Positive Ports: {0}", positiv);
                Console.WriteLine("Negative Ports: {0}", negativ);

    Why are there some users that cannot listen for any connection at all? What can I do to allow all players to listen to connections?

    Thanks in advance!
    Neph

    #2562
    Anonymous
    Inactive

    So firstly there are a large number of operating system reserved ports in the range 0-1024, see http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers. e.g. It is generally considered bad practice to even attempt to use ports in this range as it can cause some operating system features to malfunction.

    As to your specific problem please tell me what the specific exception type is that is being thrown?

    Regards,
    Marc

    #2563
    Anonymous
    Inactive

    An unhandled exception of type ‘NetworkCommsDotNet.CommsSetupShutdownException’ occurred in NetworkCommsDotNetComplete.dll
    Additional information: It was not possible to open port #PORTNUMBER on [IP]. This endPoint may not support listening or possibly try again using a different port.
    The program ‘[8020] PROGRAM.exe: Managed (v4.0.30319)’ has exited with code 0 (0x0).

    That’s the message I get on every port tested by a certain user. However, on most clients the program will just find a hell of ports that can be listened on.

    Regards
    Neph

    #2564
    Anonymous
    Inactive

    What happens if you let NetworkComms.Net choose a port randomly:
    Connection.StartListening(ConnectionType.TCP, new IPEndPoint(IPAddress.Any, 0));

    It is also important to be aware that some operating systems, or applications, install network adaptors which cannot be used for listening, in windows an example is some IEEE extensions. If you attempt to list on these adaptors on any port then an exception is thrown. You have several options:

    1. Do the above, and allow networkcomms.net to select a random port.
    2. Create listener instances yourself:

    //Get a list of all local endPoints using the default port
    List<IPEndPoint> desiredlocalEndPoints = (from current in HostInfo.IP.FilteredLocalAddresses()
                                            select new IPEndPoint(current, 0)).ToList();
    
    //Create a list of matching TCP listeners
    List<ConnectionListenerBase> listeners = (from current in desiredlocalEndPoints
                                                select (ConnectionListenerBase)(new TCPConnectionListener(NetworkComms.DefaultSendReceiveOptions, 
                                                    ApplicationLayerProtocolStatus.Enabled, 
                                                    listenerSSLOptions))).ToList();
                
    //Start listening for incoming TCP connections
    Connection.StartListening(listeners, desiredlocalEndPoints, true);

    3. Only allow adaptors that have specific IP ranges, this modifies the behaviour of the start listening override you are using:

    HostInfo.IP.RestrictLocalAddressRanges = new IPRange[] { new IPRange("192.0.0.0/8") };

    Give the above a go, if you still have problems please post back.

    Regards,
    Marc

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.