473,898 Members | 3,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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...
Nov 20 '05 #1
1 1475
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.


Made by Kevin Yu
Private Const WSADESCRIPTION_ LEN = 256

<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure WSADATA

Public wVersion As Short
Dim wHighVersion As Short

<MarshalAs(Unma nagedType.ByVal TStr, sizeConst:=WSAD ESCRIPTION_LEN +
1)> _
Public szDescription As String
<MarshalAs(Unma nagedType.ByVal TStr, sizeConst:=WSAD ESCRIPTION_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
wVersionRequire d As Integer, ByRef lpWSADATA As WSADATA) As Integer

In your codes you can use it as:

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

I hope this helps a little bit?
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: DaM | last post by:
Hi guys, I'm having this problem with my ASP.Net application: I was testing the whole site, and it seem to work fine. Fast and stable, but suddenly it stopped working and this error occurred: "Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached."
by: Thomas | last post by:
hello, which is the easiest way to check if there is a lan connection available. i have to go to a network share in my lan - but if the notebook is not connected to this lan i would like to stop some things in my app. is it a ping? - how can i check the result a ping is returning? Thomas
by: Agnes | last post by:
in form_load, i will new a sql connection ,fill in the dataset and then close the connection. I use Netstat to check the status. (1)Open the form , The status to the SQL server is "ESTABILISHED" (2)Close the form, The status is "TIME_WAIT" (3)WAIT a sec. that thread is disappear . my question is , I had closed the connection after fill in , WHY the status still become "ESTABLISHED" ? , if the user open 10 forms, there will be 10 thread...
by: Nuno Magalhaes | last post by:
How to check for a closed http socket without losing any data? (MSDN says to send something to server). Somewhere in my code (after sending the http header in plain text) I'm doing a loop with: Loop:---------------- Socket.Receive //receive http data chunks Socket.Send //'/r/n' data to check if connection is active ------------------------ The problem is that when connection is closed by the http server, the send socket function...
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database I use System.Data.Common.DBConnection and .DBCommand. How can I keep aware from connection losses (network not availeable, db-server not available...)? Are there any strategies to detect this broken connections, and how can I
by: Earl | last post by:
Is there any sort of check that can be done to see if a particular instance of SQL Server is present? I already call a method to check for connection -- if no connection, I have the user re-enter server settings (server name and database name). But the connection check is made by calling for a scalar value in the database. What I'd rather do is graduate the error messages: 1. No server installed 2. Specified database name not installed...
by: Fred Zuckerman | last post by:
I have a A2K database that includes some linked tables (these links are SQL views). Sometimes there are "issues" with the SQL server and the users receive a timeout error whenever they try to access those records. The timeout error occurs after 60 seconds. Many times the user has given up and used ctrl-alt-del to end task thinking their computer has locked up. I suppose I could change the default timeout from 60 seconds down to 30...
by: fniles | last post by:
I am using VB.Net 2003 and MS Access (connecting using OleDBConnection). I read using DataAdapter and DataSet, not DataReader. When many people try to access the database at the same time, I get the error "ExecuteReader requires an open and available Connection. The connection's current state is Open, Executing." I do not use ExecuteReader, why the error says ExecuteReader. What does it mean ? When I get this error, is there a way for me...
by: jaishu | last post by:
Hi all, I am in the process of developing a small Access application. i have the table locally in Access and I am using the following code to get the recordcount ( or to check if any record exists), but when i check for rst.eof condition, it is always true..but when i actually run the query i see, many rows returned, i m not clear about how to specify the connection parameter with the recordset, as i m using the tables locally, but i...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.