Home Forums Support Cannot listen on certain connections Reply To: Cannot listen on certain connections


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, 
//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("") };

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