Just wanted to start by saying I'm pretty new to C programming, so I'm not sure if this is possible. Basically I have a broker running that can have multiple publishers/subscribers connected to it, and I need to be able to ping the broker from inside the publishers/subscribers so that I can determine if the connection is bad. Can this be done? Or would there be a better way for determine a bad connection from within a C program?
Asked
Active
Viewed 133 times
-1
-
This question is way too general, but my best guess would be that as long as you are connected, your client can send a specific command packet and measure the time to get an answer from the server(broker). – dvhh Oct 02 '17 at 02:37
-
you can check this : https://stackoverflow.com/questions/8189935/is-there-any-way-to-ping-a-specific-ip-address-with-c – Denis Enrico Hasyim Oct 02 '17 at 04:00
-
The ping program is normally written in C. Therefore, yes it can be done. However, you have to decide what you’re checking for. Are you looking to see if the server you’re connected to is OK, or whether the program you’re connected to is OK. The program could be non-responsive when the machine and network is fine. The checking techniques will be different. – Jonathan Leffler Oct 02 '17 at 05:24
-
Please [edit] your question to show [the code you have so far](http://whathaveyoutried.com). You should include at least an outline (but preferably a [mcve]) of the code that you are having problems with, then we can try to help with the specific problem. You should also read [ask]. – Toby Speight Oct 02 '17 at 09:38
1 Answers
1
Im sure there is a way to determine if a connection is bad based on error codes your socket library gives. You could also try using a system() call to the OS ping command.
JoyStickFanatic
- 32
- 6