I'm trying to write a program that reads input events(keyboard, mouse, touch etc) from a linux computer and send it over tcp to another linux computer, which first creates virtual input devices corresponding to the ones on the server machine, receives the events, and runs them.
I've finished writing all the reading input and creating virtual devices part, but I'm a bit confused about how I should send the events over the network.
I was thinking about a generic struct that the server sends whenever any kind of event(not limited to input events) happens. Something like
struct generic_event {
unsigned long event_type; /* Client uses bit masks to get the event type
(event types might include: addition of a new
device(device plugged in while the program was
running), mouse movement, keyboard key etc)*/
struct device_info
dev_info; /* Store the capabilities of an input device, used when
event_type is adding a new input device*/
struct input_event ev; /* struct for describing an input event*/
/* etc etc*/
};
But this is highly inefficient. The device addition event would rarely be sent, and for those maybe 2 or 3 times, all those extra bytes of zeroes in the device_info struct would be sent over the network.
So, what would be the ideal way of doing this?