heart beat in console program
I have a code that implements multi-threaded socket communication with c++, and I want to add an additional heart beat code. However, when the server is waiting for a client message through recv for each thread, how does make run the heart beat? If you let me know the logic or hint, I want to try it.
recv enter infiniteloop, and waiting until recevie message from client.
i wanna make heart beat code. but It can't since recv.
this is all code: https://ideone.com/TWRvnB
Ideone.com
Ideone.com
Ideone is something more than a pastebin; it's an online compiler and debugging tool which allows to compile and run code online in more than 40 programming languages.
15 Replies
C++ and C# are two entirely different languages
$cpp
We're partnered with Together C & C++, check them out here: https://discord.gg/vnyVmAE
If C#, How to resolve this problem?
I think idea(algorithm) is same whatever any langauge
There are different heartbeat implementations, most of the time you can just send a single byte and that is the heartbeat, each 15th second or so.
yea, i know, but since receive, I can't image idea. because
Threads on the server enter an infinite standby state through recv, so that any thread cannot send a message to the client by heartbeats after a certain period of time.
Huh?
Could you understand my meaning?
you're sending and receiving on the same thread?
upload code is not include thread about heart beat
i didn't look at the code, i don't understand what the problem is
Ideone.com
Ideone.com
Ideone is something more than a pastebin; it's an online compiler and debugging tool which allows to compile and run code online in more than 40 programming languages.
i'm not asking for more code, i'm asking for you to explain the issue more clearly
i don't know C++ that well anyway
Even if a heartbeat thread is created after acceptance or before acceptance, it is executed only at the beginning, but is not executed again after being executed once. This is because each thread is in a standby state through receive.
this is my issue
am i missing something or is your heartbeat thread not a loop?
if you don't use a loop it's only going to execute the code once
oh thanks, I understood. Actuall I didn't know thread execute in the loop continuosly