Thonord
Member
- Joined
- Oct 25, 2012
- Messages
- 23
- Programming Experience
- 10+
I'm trying to check if a server is present on the network
I thought the client could create a non blocking socket, connect to it within a Try Catch and either get a response or an exception.
The code below demonstrates my thoughts. For testing purposes I use a "Hard Wired" IpAddy where I know there is a server, its running and it works.
But! I only get an exception. I never get a True!
Why does not my code return True when the is a running server at 10.0.0.53:5066 ?
Tom
I thought the client could create a non blocking socket, connect to it within a Try Catch and either get a response or an exception.
The code below demonstrates my thoughts. For testing purposes I use a "Hard Wired" IpAddy where I know there is a server, its running and it works.
But! I only get an exception. I never get a True!
VB.NET:
Private Function CheckServer(ByVal MyServer As String, ByVal MyPort As Integer) As Boolean
Dim Address As IPAddress = IPAddress.Parse("10.0.0.53")
Dim EndPoint As New IPEndPoint(Address, 5066)
Dim TestSocket As New Socket(EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
TestSocket.Blocking = False
Try
TestSocket.Connect(EndPoint)
Return True
Catch ex As Exception
Return False
End Try
End Function
Why does not my code return True when the is a running server at 10.0.0.53:5066 ?
Tom