Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Actually my scenario is this socket connection is dedicated. i have to check the connection before for every string sending, is that below statement can be able check the connection as my case or not?

if(0 != getsockopt(l_ClientSocket, SOL_SOCKET, SO_KEEPALIVE, &error_code, &error_code_size))

Hence, this case will perform only transmitter mode.

What I have tried:

getsockopt will check the connection, that i seen in google but not working
Posted
Comments
Greg Utas 22-Mar-22 8:05am    
What do you mean by "check the connection". It will certainly fail if the socket handle isn't valid, but that's about it. Because it only reads the keepalive option, it won't detect whether the socket is connected or whether a disconnect is pending.

1 solution

Ping to a known location that you are confident is reachable.

If the return indicates that the location is unavailable, then ping somewhere else.

Do this a few times, once to each location, and if multiple locations are unavailable, then you probably do not have a connection.

Ping is very fast and usually has a very tiny packet size, thus it should go through even an old dial-up connection without too much difficulty fast.

A ping via a CLI might work for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900