Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

winsock client/server

Status
Not open for further replies.

rann

Programmer
Sep 13, 2001
86
0
0
US
Hi,
When my winsock client opens i need to find if the server
is listening (or is up).before it connects to it. how to do this.

for example a server can use "tcpserver.listen = sckListening" to find if the client is listening. I want the opposite to happen.


Any help or links would be helpfull,

Thanks in Advance.
Rann.

 
If you want to see if the server is up, just ping it. If you want to see if the listener on the server is listening, that's a different story. Snaggs
tribesaddict@swbell.net
Life can only be understood backwards; but it must be lived forwards.
 
Why not just try to connect to it?

You could have a small routine on the server side that sends back a status.

For exmaple, you could set the timeout on the client to be 2 secs (assuming you can get a connection in that time frame). Then issue a connect from the client.

Then send a status request to the server. If you get back "Listening" then the server is up and listening. If it times out, you know it wasn't running, or didn't have enough time to connect.

1. Client would connect and send "ListenerStatus" as the message.

2. Server would accept connection.

3. Server would read input buffer.

4. If message in buffer = "ListenerStatus" then send back "Listening" to client.

5. If client got back "Listening" then inform the user the client is listening. Then disconnect.

6. If the connection timed out then inform the user the client is not listening. Snaggs
tribesaddict@swbell.net
Life can only be understood backwards; but it must be lived forwards.
 
Well, since there is no method for the Winsock control to check if the server is listening, you can add a custom method(function) and send a simple request to the server.

On the server side while it is listening, on receipt of this request, it can send an acknowledgement to the client.

The client can trap this ACK and assume that the server is up else the server is down.

In other words you are simulating the Request/Response flow here from client side.

Let me know if this helps.
 
Opps, in lines 4 and 5, it should be that the SERVER is listening, not the client. Snaggs
tribesaddict@swbell.net
Life can only be understood backwards; but it must be lived forwards.
 
:).....That makes more sense Snaggs. And I guess I was saying the same thing as you.

Hope this works for rann.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top