- This topic has 13 replies, 4 voices, and was last updated 10 years, 3 months ago by
Anonymous.
-
AuthorPosts
-
January 9, 2014 at 02:41 #1411
Anonymous
InactiveSo 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.
May 19, 2014 at 14:46 #2588Anonymous
InactiveI 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 10.255.231.107. 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?
Thanks.
Martin
May 19, 2014 at 19:12 #2592Anonymous
InactiveHeya 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,
MarcMay 20, 2014 at 00:38 #2595Anonymous
InactiveHi 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); _listeners.Add(listener); } 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); } }
Regards.
Martin
-
AuthorPosts
- You must be logged in to reply to this topic.