I’m looking into making a tcp client in C.
But before I start I would like some advise from you.
The client is for controlling lights and other devices.
With this client I will need to send commands, but I can also receive events when a light is turned off by someone.
Just sending commands with sockets is no problem.
But at the same time I have to read for incoming packages.
How is this best solved?
Do I need to use threads or can I solve this with something like libevent?
How do most people implement something like this?
This library should be as portable as possible. (linux, unix, windows, …)
(I’m not looking for code, but just a best approach)
BSD sockets are bidirectional, and you can check if your socket has an incoming data or not by select(2)
IMHO using libevent is too much for your purpose. It’s nice but you have long way to go to realize its power. Actually libevent is a wrapper for select(2) or its improved successor epoll(2) etc.