Home Forums Support Unable to create a TCP connection

Viewing 4 posts - 11 through 14 (of 14 total)
  • Author
  • #1411

    So I figured it out. I’m a little embarrassed to say that I think the whole problem stemmed from a typo. Thank you for helping out. If nothing else hopefully this serves as a helpful guide for others troubleshooting any issues.


    I want to start listening on all adapters with the following code:

    _listeners = Connection.StartListening(ConnectionTypeToUse, new IPEndPoint(IPAddress.Any, ServerPort));

    I am using only TCP connections.

    But in certain scenarios there is the following error:
    “It was not possible to open port #8000 on This endPoint may not support listening or possibly try again using a different port.”

    I have seen this error also when a VPN adapter is present.

    My restriction is that I must use the specified TCP port because the clients will connect to this port from the same configuration.

    Is there any other possibility to start listen for each individual adapter?




    Heya Martin,

    There are a few ways of achieving this,

    1. Specify the allowed IP addresses using:


    If you do this before calling start listening you can easily exclude adaptors that are not required.

    2. The more rigorous approach is something along these lines:

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

    Obviously only select adaptors that are required. Also see overrides to StartListening that only take a single ConnectionListenerBase. This gives you adaptor level control over listening.



    Hi Marc,

    thanks for the hint.

    I solved it with a “failsafe” approach where each failed listener gets a log entry:

    _listeners = new List<ConnectionListenerBase>();
          List<IPAddress> filteredLocalAddresses = HostInfo.IP.FilteredLocalAddresses();
          if (filteredLocalAddresses == null || filteredLocalAddresses.Count == 0) {
            throw new ApplicationException(String.Format("No filtered local addresses available to start listener for server of type {0}.", GetType().Name));
          foreach (var ipAddress in filteredLocalAddresses) {
            var endPoint = new IPEndPoint(ipAddress, ServerPort);
            try {
              Log(String.Format("Starting listener on end point {0}", endPoint.ToString()), TraceEventType.Verbose);
              var listener = new TCPConnectionListener(NetworkComms.DefaultSendReceiveOptions, ApplicationLayerProtocolStatus.Enabled);
              Connection.StartListening(listener, endPoint);
            } catch (Exception ex) {
              Log(String.Format("Listener on end point {0} could not start due to the following error: {1}", endPoint, ex.Message), TraceEventType.Error);



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