Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Winsock Tcp Connection Check

Hello everybody.
I have written in VB6 a server-client chat-like application based on the winsock component.
I establsh a TCP connection to each client using an array of Winsock controls.
Every time a user connects to the server, it sends to every connected user the updated list of the connected clients.
The only thing i can't figure out is how to check whether my clients are still connected (if somebody shuts down the applicatio properly there's no problem since the client sends a packet telling the server it is shutting down, but if the application freezes or the computer is resetted this doesn't work, obviously). Is there anyway I can check if the other host is "still there"?
Thanks in advance

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
VB6 - Winsock - Check Connection

I have a VB6 client/server app using Winsock features and am having some problems with it.

On the client side, I have a series of commands like the following:

If Winsock1.State = sckConnected Then
Winsock1.SendData ("Ad1Break")
TotalSent = TotalSent + 1
Label2.Caption = "Total Script Commands Sent to Server: " & TotalSent
End If
End Sub

However, after the client has been running for a long period (anywhere between 30 and 1 1/2 hours) without sending any commands to the server, even though it reports its status as CONNECTED, it does not successfully transmit the command to the server.

Is there any other way to test the connection before sending over the command to ensure that the connection is still active and the server is listening and will receive the command.

Connection is made in the following script:

If ConnectToServer1 = 1 Then
If Winsock1.State <> sckClosed And _
Winsock1.State <> sckConnected Then
End If
If Winsock1.State = sckClosed Then
End If
'Report connection status
If Winsock1.State = sckConnected Then
Label1.Caption = "Connected to " & EncoderHost1 & ":" & EncoderPort1
Label1.Caption = "Attempting to connect to Script Command Server: " _
& EncoderHost1 & ":" & EncoderPort1
End If
Label1.Caption = "Not connected to Script Command Server: Running in stand-alone mode"
End If

Thanks so much for your help.


Winsock Check Connection Problem
i'm using vb6

i'm doing a chat program and i have made two project, "Host" and "Client".

The "Host" can connect and disconnect from the "Client" under normal condition.
But when the computer, which have the "Client" program, power trip, the "Host" is still detect as connected.
When the computer resume, the "Client" cannot connect back.

I would like to ask, how to check a connection ? Then if the connection is lose, close the winsock. Just like the computer power tirp, the other party closes the winsock.

Below is the code i tried but is still detect as connected, even one party is gone.
Code:Private Sub Timer1_Timer()
Dim index As Integer
If Winsock1(index).State <> sckConnected Then
Me.Caption = "Not Connected"
Me.Caption = "Connected"
End If
End Sub

Thanks for helping me.

Quick Way To Check If A Winsock Connection Is Open?
first off, im using a control array of winsock controls. they are all listening on the same port.

now, the problem is, whena new person logs on, a new isntance of the control i created. this is fine, untill 5000 logins later your server is out of ram. i need an effective way of unloading the winsock controls after they lose their connection.

How Can I Change The Timeout Check For TCP_IP Winsock Control As The Connection Is Disconnected?
Hi! Everybody!
I want to know how i can change the timeout check for the TCPIP winsock control as the connection is disconnected. Now i find when i connect two computers through TCPIP and if the connection is disconnected, one computer know the connection is cut at least 60seconds later and another cannot know the connection cut. I want to change the timeout to a smaller value. How can i achieve this?
Thank you very much!

How To Check Connection To DB Is Connected And How To Check Record Set Really Have Result?
Code:Set DB = New ADODB.Connection
DB.ConnectionString = "Provider=" & DB_PROVIDER & ";" & _
           "Network Library=DBMSSOCN;" & _
           "Data Source=" & strSQLServer & _
           "; Initial Catalog = " & strDatabaseName & _
           "; User ID = " & strUserID & _
           "; Password = " & strPassWord
debug.print DB.state

Question : How can I check is the DB connection really connected (active)?
i use DB.state
and the result show 1
is it ok, if not please give suggestion?

sSQL = "Select * from table1"
  Set RS = New ADODB.Recordset
  RS.ActiveConnection = DB
  RS.Source = sSQL

debug.print rs.recordCount

Question : I want to know how many record were find from the query. When I use debug.print rs.recordCount, it show -1. is it mean there is no record found? Should I use instead?

I am confussing how to get record set and why there is no result from the query... something wrong?

Winsock State 8 - Peer Closes The Connection Leaving Winsock High And Dry
I am debugging some web/proxy-serving code. I am stumped.

I get Winsock state 8 - Peer is closing the connection
Then Winsock error message wrong protocol or connection state.

It seems to me that Winsock closes before it can finish sending all of its data.

How can I keep Winsock in state 7 - Connected?


Winsock Connection Prob: &"Request To Connection Time Out&".
Hi All,

I am developing chat application like Yahoo and MSN messenger. Also i have almost completed it. I have two applications one is server appliation which will be run on chat server machine. the other is client appliation which will be used at any corner of the world.

Its working fine on my network. Ya, it is also working fine over network but with some misbehaviour. Sometimesm, it allow someone to login and sometimes it doesn't and gives "Request to connection time out" error.. I can't find the reason y it is happening.

I have developed this in visual basic and used winsock control.

Winsock Connection Prob: &"Attempt To Connection Time Out&".
Hi All,

I am developing chat application like Yahoo and MSN messenger. Also i have almost completed it. I have two applications one is server appliation which will be run on chat server machine. the other is client appliation which will be used at any corner of the world.

Its working fine on my network. Ya, it is also working fine over network but with some misbehaviour. Sometimesm, it allow someone to login and sometimes it doesn't and gives "Attempt to connection time out" error.. I can't find the reason y it is happening.

I have developed this in visual basic and used winsock control. Any idea regarding this may help me out.

Check Connection
Does anyone know if there is any way I can use VB to determine if the user has a connection to the web.

I want to run a code that retrieves external data from a web site, but it would will only run if there is a connection present, if not it will display a msgbox stating that they need to connect??

How To Check For Net Connection?
Whats the quickest and easiest way to check for a Internet Connection? I want it to return True or False, that simple.

Of course, I dont mean LAN, but Internet. If its a private IP (like 169.x.x.x) then I want it to be FALSE as well. You get the picture

Check For Connection
FE database on laptop that has linked tables to the server.  AutoExec macro initiates the links.  My problem is that if not connected to the server the db fails because it cannot find the links.

1.  How can it check for a proper link prior to running the AutoExec macros?

2.  If a connection IS NOT found then ignore linking the tables.

3.  If a connection IS found then continue with the links.

Thanks for any help.

Check If Connection Is Used
I wanna check if the connection is already made.

Global QcDb as new ADOdb.Connection
Global QcRs as new ADOdb.Recordset
QcDb.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & dbstring & ";"



Check Connection
Do anyone know how to write a VB code to check who is connected to our share driver. A code that can do similar task as Netwatcher. Appreciate any reply.

How To Check Dial-up Connection?
I have made an application which connects to another (remote) computer using DialUp Connection (aon application side) and Incomming Connection on remote computer side.
I want to check every 10 seconds if this connection still exists or not (using timer to raise control procedure). I'm using some code I have downloaded previously ....

Public Function ActiveConnection() As Boolean

'function checks registry for
'an active connection

Dim hKey As Long
Dim lpData As Long
Dim nSizeData As Long
Const sSubKey = "SystemCurrentControlSetServicesRemoteAccess"
Const sKeyValue = "Remote Connection"
sSubKey, _
lpData = 0&
nSizeData = Len(lpData)
If RegQueryValueEx(hKey, _
sKeyValue, _
0&, _
0&, _
lpData, _
nSizeData) = ERROR_SUCCESS Then
ActiveConnection = lpData <> 0
End If
Call RegCloseKey(hKey)
End If
End Function
As I'm using Windows 2000 Pro ... I think that something is wrong with Registry keys because this function above returns False although connection exists (System Tray indication) or ... hm, as it is not connection to Internet but to remote computer directly I wander if it is related to this problem.


Check Network Connection
How could one do a simple check to see if a network connection is active? What references and components (if any) do I need?

Thank you!

Check Internet Connection

I have an API call that tells me whether or not I have an internet connection which works if I pass it a valid http: address.

I cannot get it to work when I pass it an IP address instead. Is there any other way I can check for this without having to introduce the INET control on my form? Any help will be appreciated.

Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long

Private Sub Form_Load()
' This works
If InternetCheckConnection("", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
MsgBox "Connection to failed!", vbInformation
MsgBox "Connection to succeeded!", vbInformation
End If

' This DOESN'T work
If InternetCheckConnection("", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
MsgBox "Connection to failed!", vbInformation
MsgBox "Connection to succeeded!", vbInformation
End If
End Sub

Internet Connection Check
I have this in a class module:

Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef _
lpSFlags As Long, ByVal dwReserved As Long) As Long
' return True if there is an active Internect connection
' optionally returns the connection mode through
' its argument (see INTERNET_CONNECTION_* constants)
' 1=modem, 2=Lan, 4=proxy
' 8=modem busy with a non-internet connection
Function IsConnectedToInternet(Optional connectMode As Integer) As Boolean
Dim flags As Long
' this ASPI function does it all
IsConnectedToInternet = InternetGetConnectedState(flags, 0)
' return the flag through the optional argument
connectMode = flags
End Function
Now I want to check in my program if there is a connection. I do it like this:

If IsConnectedToInternet = True Then MsgBox "Connection is there"
But it ain't working. I do not get the message. Please advise. Thanx in advance

Check Connection...IF Statement
I would like when the user click on exit the prog. will check is the Inet is still connected, if so display a messeage "disconnecting.." & the Unload me but if their is no connection the just "unload me"
This is what I have.....

Private Sub mnuexit_Click()
IF Inet1.URL <> "" Then ' if an url is present in the box
Inet1.Execute , "CLOSE" ' issues the QUIT command
message.Caption = "Disconnecting..."
Unload Me
End IF
If Inet1.Execute , "CLOSE" then
Unload Me
End If
End Sub
Thnx 4 helping

Check For Internet Connection?
Internet.Execute STRCONN, _

Internet.Execute will fail if there is no internet connection, is there a way to check for a connection? Also, the program I'm writing is transferring semi-large (~1.5mb) files from internet to desktop. What happens if the connection is terminated in the middle of a transfer? As you all can see, I'm a n00b at error handling.

Check If Connection Is Open
I people,
How can I check if my connection is open....???

I already tried :

con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=DesenvolvimentoRh Vb v.1.0compactador.mdb;Persist Security Info=False"
con.CursorLocation = adUseClient
con.Mode = adModeReadWrite

if = true then


UID Check For ADOBC.Connection
How can I tell if a UID is needed for a database connection without trying to use the connection and have it crash? Thanks.

Check Connection Status
I have a vb6 application that connects to a sql2005 DB.
I want to add some error checking for any problems when a pc looses its
connection with the server, or if the server closes down the connected process.
I have some code that just before i get a recordset using the connection i check the connections status to see if it is still open. if it is then i use it and if it is not then i go off and create a new connection.
However this does not seem to work when i mimik a lost connection by in sql2005 activity monitor killing the process manually mid application.
I am using the cn.state to check the connection and after the killed process the app still thinks the state is 1 (open).
There does not seem to be a connection.refresh, what can i do to catch this error?

Thanks in advance

Database Connection &amp; Check
Hi there,

I am creating a vb program to help my customers admistrate their web sites build using asp. i'm great at asp vbscript but coming to vb alone is getting a little tirsome.

Can someone explain how I can try and connect to an sql database. If it fails then I want it to tell a label "failed" which I know how to do, just getting the result is the problem. and of course if it passes then tell it ok. Just checks to make sure we can connect to the sql server before loading their database etc.

I was getting loads of problems until I ticked a setting in references. now those messages have gone, I managed to connect to the database and it said failed, which I knew was incorrect as I know the database is there.

Can some one help? All I want is that when the form loads it will check to see if the sql server is reachable. My coding is below:

Note: You may notice that the database and username are the same, this is correct, my host creates the database in the same username as the rest of your accounts.


Private Declare Function InternetCheckConnection Lib "wininet.dll" _
Alias "InternetCheckConnectionA" _
(ByVal lpszUrl As String, _
ByVal dwFlags As Long, _
ByVal dwReserved As Long) As Long

Public Function CheckInternetConnection(ByVal strURL As String) As Boolean
CheckInternetConnection = (InternetCheckConnection("", _
End Function

Public Function CheckSQLServer(ByVal dsnname As String, ByVal dsnuser As String, ByVal dsnpass As String) As String

Dim Connection As ADODB.Connection
Set Connection = New ADODB.Connection

Connection.Open "Driver={SQL Server};Server=" & dsnname & ";Database=" & dsnuser & ";Uid=" & dsnuser & ";Pwd=" & dsnpass & ";"

End Function

Private Sub Continue_Click()

If IntConnStatus = "OK" And DataConnStatus = "OK" And DSNConnStatus = "OK" Then

Check.Visible = False
Login.Show vbModal, Check

End If

End Sub

Private Sub Exit_Click()
End Sub

Private Sub Label6_Click()

End Sub

Private Sub Form_Load()

If CheckInternetConnection("") Then
IntConnStatus.Caption = "OK"
IntConnStatus.ForeColor = &HC000&
IntConnStatus.Caption = "Failed"
IntConnStatus.ForeColor = &HFF&
End If
If CheckSQLServer("eycd", "gRoberts", "amanda") Then
DSNConnStatus.Caption = "OK"
DSNConnStatus.ForeColor = &HC000&
DSNConnStatus.Caption = "Failed"
DSNConnStatus.ForeColor = &HFF&
End If

End Sub
Thank you


Internet Connection Check
How would I check if im connect to the internet or not? And if its not, I want it to check again until the computer is connected. Im guessing I could probably try and connect to google by using winsock... But wouldn't google ban my ip if I do that too often?

Any ideas?

How To Check The Connection Open
How can i check that the database connection is open or not.
if connection is open, then how to close ?

i m using ADO 2.1 library

Check Connection Connected...
how to check how many connection currently connected to access database?

Check Access Connection Using Vb
how to check how many connections connecting to an access db using vb code?

Check For Connection Problems
I'm busy writing an app to check if there are any problems with the internet connection. Those are common unfortunatly @ my place because sometimes my ISP performs some maintenance and alot of times my network plug doesn't seem to connect properly. So I want to write a simple utility that puts an indicator on the taskbar which signals when there's packetloss, or when my connection to the server is lost, or when the connection to the ISP has been lost. Easy thing of course, just ping my ISP every second and if that starts to fail, ping the server. If the last one fails you know if it's the ISP of your network. But of course, that would be to easy, I have to do it the hard way . I want to make it run on any version of windows from win98 to win2003. Futher the program should just run without a user having to configure it. So the user shouldn't fill in the IP of his ISP but just install it and it should work.

The problem is this, first I should find the ISP which can differ from place to place and the user should have the ability to type it but that is more like a solution in case that we can't find the ISP.
How to find the ISP?
I thought myself to find out if we are directly connected to the internet or via a server/router. We should find the IP of that thing then which must be on the local comp of course . Then we should perform a traceroute and the first address after ours, or our server/router should be the ISP, right?

But well, what to traceroute then? I thought myself, because it's a pretty stable server. However, although quite unlikely, it Could move, or be renamed or just totally removed and then the program traceroutes a non existing IP, thus the traceroute won't come any futher then the router and wouldn't find the ISP. Somewhere else I found a little piece of text saying that WinInet's internal server database has an entry for the nearest server, which should be the ISP (or am I wrong here?) so that could be a better solution then. But how to find it?

Well if someone knows an answer on this question, let me know please. I'm not that good in network programming unfortunatly, so if anyone sees an alternative solution, that's also kindly appreciated .

Check ODBC Connection
is there a way i can check an ODBC connection before i actually attempt to connect to it? I would need to check that it is actually there on the PC and then test connect it to make sure it worked... I could just trap the error.. but i was wondering if there is a better way to do it

Best Way To Check For Active Connection
HeY, I made a Winsock Server / Client Program. I need a way to the client to constantly check for an active connection. Would I good lOop work. I toought I would ask for advice before doing anything. Thanks

Check For Network Connection
any code out there to test for a good network connection ?

I want to make something to run at startup but then check
if there is a network connectoin.. if yes then run up the
instant messenger code.. if not bail out... I guess I could make
something to just try a ping and then go from there... got me..

any suggestions ??

Check For Internet Connection?
is there any way opssible to check for internet connection? then if present go on to next step and if not give error message?

Check For Network Connection.
I am writing a program that will run on both laptop and desktop using NT and 98. I need to do a check to see whether or not a connection to a network is present to determine whether the user is using the laptop or desktop.
Any suggestions?

Check Connection Status
I wrote a program a short while ago that checks the connection status of a computer over the internet. However, it uses the settings stored in Internet explorers connection settings, and as i have a firewall setup, it uses LAN settings as default. But i want to check the dial up adapter for a connection so i can show whether the computer is connected to the internet or not. Thiswill be indicated by traffic lights in an icon on the systray. Green light for open connection and red for closed, and amber for when the program is first loaded.

Can you tell me how to explicitly check just dial up adapters for a connection or whether a dial up connection is open on a machine.

Oh and this application will run on the server so you dont have to detect the connection through the network

Check For An Interent Connection
How do we accurately find out if we are connected to the Internet from eighter a dial up connection, cable modem, or through our local LAN. Any good piece code would be helpful. Remember, it should be able to figure out if you have a gateway to the Internet or not.

Check For Internet Connection?
I have one part in my application where the user actually goes on the web using the WebBrowser control. How can I test for an internet connection and if not give them the option to connect?

How Can I Check If There Is An Internet Connection?
I'm writing an HTML parser... I need my program to be able to check if there is an internet conection before it tries to download any html, how do I do this?

Check For Dialup Connection
Can anyone tell me if there's a way to check to see if a dial up connection is already active with VB, and establish one if there isn't? It's for my cheapie browser, and I'm getting lazy in my old age

Check For Email/Net Connection?
Does anybody out there know how I would check to see if a system has an internet connection set up (I don't mean currently connected)?

Also is there a way of determining whether a machine has e-mail set up?

How Can I Check If There Is A Dialup Connection
hello all

i want to know that :

1- how i can check if there is an active dialup connection?
2- how i can get the password of the dialup connections by vb code?

thanks in advance

Ayman Obayda

Check For Lost SQL Connection
Ideally, I'd like to be able to check that a SQL connection is still active 'occasionally'. The ideal solution would involve detecting when the application deactivates or re-activates so that I can then check the status of the connection.

It would not be practical/efficient to change the activate event in every form across the application unless I can trap the fact that the activate has come from outside the application rather than within it.

Thanks in advance.

How Do I Check My Network Connection(IP)?
Not sure where to ask this question. I have searching for a while and not sure what to search on either. So I thought I would post the question here to start with.

What I am trying to do is write an utility that is triggered from a timmer(I can handle this piece), but what it needs to do at event time is to connection(or at least test the connectivity) of a given list of host names. I am attempting to log when network connectivity is dropped from the client devices. I am writing this in VB6.

Any ideas of how to handle. I am looking for an easy to understand method and not looking to BLOAT the utility as it needs to run on a mobile devices running Windows XP Embedded.

Thanks for your suggestions and help.

Mickey A

Edited by - cmalberto on 11/15/2005 7:28:22 PM

Check If RDO Connection Is Still Active
I'm having a problem with VB6 causing a major error and closing up my project when it tries to execute an insert query.

The application is already using RDO and this statement is executed multiple times before the program closes.

Is there a way to check if the connection is still active before I execute this query?

This is the execute statement I'm using:

glblObjConnectionEPC.Execute sSQL

So I need a possible check on the connection before hand.


Check If Connection Is Open
i wonder if anyone can help.

i have a form where someone can search the database to see if a username already exists, before creating a new account. when it has searched and the recordset is still connected, the Clear button will close the recordset connection (rs.close). however, if i click Clear without having it open, i get an error. my question is, if it is possible, how do i make an IF statement to check to see if the recordset is currently open, and thuse closing in, or if it is close, then take no action?

Check Connection To Internet
How can I check form VB code if the computer is connected to internet, and if not, to connect him?
I used Internet transfer control and OpenUrl method to download a file, and if the machine is not connected , the control
doesn't wait for connection.

Check Network Connection
I am migrating some code, and I need to put some funtionality in the code that checks to see if this workstation is connected to a network:

If (networkconnectionexists) = true then
end if

Any help is appreciated, Thanks.

How To Check My Internet Connection
How can I check if my computer is connect to the internet?

Check Internet Connection
Hi Everybody,

Wish you a happy year.

I have a problem and I hope someone can help me as early as possible. I want to check whether the machine was connected to Internet programmatically. Could anyone suggest me how to do this?

Thanx in advance.

With best wishes

Copyright 2005-08, All rights reserved