c++ tcp multithreaded client/server - how to communicate with threaded sockethandler?
<p>I made a multi-threaded client/server in c++. It works fine. The 'protocol' is text based. I have a sockethandler function (that runs threaded in an infinite loop until something happens with the connection or the client gracefully disconnects) after that thread starts the server is waiting for a new connection. Now, for this specific program I'll only allow one client at a time. Up until now the client has always been the initiator and the server responds. But I need to send the client program lots of data (not size, frequency) from other threads and I don't know how. My code is cross platform - I compile for windows and linux from the same source. The client/server code is cross platform too give or take a few lines... What's the best method to do this? queues? or are there faster methods? can someone point me in the right direction or give me some example code please?
I did try to sort it out and design-wise I'm considering adding an udp listener to the client and an udp sender to the server so that I have 2 communication channels but I don't know if that a good practice...
I currently have a socket in a thread but I only know how to use it from one direction - that's my main issue...</p>