472,142 Members | 1,229 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

how do you check that a tcp connection is available?

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
Nov 20 '05 #1
1 1414
Cor
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...ernet/ping.htm

http://www.mvps.org/vbnet/index.html...byhostname.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
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by DaM | last post: by
2 posts views Thread by Thomas | last post: by
1 post views Thread by Agnes | last post: by
2 posts views Thread by Nuno Magalhaes | last post: by
3 posts views Thread by Martin B | last post: by
2 posts views Thread by Earl | last post: by
4 posts views Thread by Fred Zuckerman | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.