how do you check that a tcp connection is available?

  • Thread starter Thread starter Eric Cathell
  • Start date Start date
E

Eric Cathell

I have a multithreaded application that is acting as a printserver. the
printers area connected to the network via IP address using a symbol
clientbridge. There are times that a printer may not be available...if that
is the case the program hangs trying to connect and wont recover on its own
when the situation is resolved.

how can i go about verifying that the connection is available before
actually connecting? or is there someway to specify a timeout period?

I have tried looping and other conditional statements, but i pegged it down
finally to the fact that if it tries to connect and cant open the connection
that thread just hangs....

thanks for you help...
Eric
 
Hi Eric,

You can Ping the IP adres.

Here is a link and a code Kevin Yu did make some times ago.

I dont know if the code works, I just copied it.

VB6
http://www.mvps.org/vbnet/index.html?code/internet/ping.htm

http://www.mvps.org/vbnet/index.html?code/internet/pingbyhostname.htm


Made by Kevin Yu
\\\
Private Const WSADESCRIPTION_LEN = 256

<StructLayout(LayoutKind.Sequential)> _
Public Structure WSADATA

Public wVersion As Short
Dim wHighVersion As Short

<MarshalAs(UnmanagedType.ByValTStr, sizeConst:=WSADESCRIPTION_LEN +
1)> _
Public szDescription As String
<MarshalAs(UnmanagedType.ByValTStr, sizeConst:=WSADESCRIPTION_LEN +
1)> _
Public szSystemStatus As String
Public iMaxSockets As Integer
Public iMaxUdpDg As Integer
Public lpVenderInfo As IntPtr

End Structure

Private Declare Function WSAStartup Lib "wsock32" (ByVal
wVersionRequired As Integer, ByRef lpWSADATA As WSADATA) As Integer

In your codes you can use it as:

Dim Data As New WSADATA
If WSAStartup(&H201, Data) = 0 Then
'Codes of your logic
End If
///

I hope this helps a little bit?
Cor
 
Back
Top