I searched for answers relevant to this, but didn't come across any. I am writing a socket program for a P2P network for which I need to incorporate some signal handling.
If I press CTRL+C while I am running the program, the program should send a "LEAVE" request to another peer.
Pseudo code:
if conditionX
dosomething(IP, port)
if conditionY
dosomethingelse(IP, port)
if SIGINT detected
sendleaverequest(peerip, port)
How can I implement signal handling here?