Home Forums Support GetConnection() In IOS Not Giving Exception Reply To: GetConnection() In IOS Not Giving Exception

#3680
Anonymous
Inactive

For anyone else who has come across this problem here is my current workaround (until the version comes out with a fix for this issue). I call the following method prior to trying to connect with networkcomms.net. Only if this method tells me something is listening do I try and connect with networkcomms.net library.

static bool IsServerAvailable(string IPOfServer, int PortNumberToTry)
{
bool SomethingListeningOnPort = false;

try
{
System.Net.Sockets.Socket sock = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,
System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
sock.Connect(IPOfServer, PortNumberToTry);
if (sock.Connected == true) // Port is in use and connection is successful
SomethingListeningOnPort = true;
sock.Close();

}
catch (System.Net.Sockets.SocketException)
{
SomethingListeningOnPort = false;
}

return SomethingListeningOnPort;
}

Andrew