For college, I am developing a local relay chat. I have to program a chat server and client that will only work on sending messages on different terminal windows on the same computer with threads and fifos.
The fifos part I am having no trouble, the threads part is the one that is giving me some headaches.
The server has one thread for receiving commands from a fifo (used by all clients) and another thread for each client that is connected.
For each client that is connected I need to know a certain information. Firstly, I was using global variables, which worked as longs as there was only one client connected, which is much of a chat, to chat alone.
So, ideally I would have some data like:
-nickname
-name
-email
-etc...
per client that is connected. However, I don't know how to do that.
I could create a client_data[MAX_NUMBER_OF_THREADS] where client_data was a struct with everything I needed to have access to, but this would require to, in every communication between server and client to ask for the id of the client in the array client_data and that does not seem very pratical
I could also instantiate a client_data immediately after creating the thread but it would only be available in that block, and that is not very pratical either.
As you can see I am in need of a little guidance here. Any comment, piece of code or link to any relevant information is greatly appreciated.
Thanks.