Home › Forums › Support › Unable to create a TCP connection › Reply To: Unable to create a TCP connection
May 19, 2014 at 19:12
#2592
Inactive
Heya Martin,
There are a few ways of achieving this,
1. Specify the allowed IP addresses using:
HostInfo.IP.RestrictLocalAddressRanges
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,
ApplicationLayerProtocolStatus.Enabled,
listenerSSLOptions))).ToList();
//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.
Regards,
Marc