Socket/server signal handling
I've been trying to create a client/server software architecture and so far it works as expected. However, I've gotten to the point where I want to do something such as private message handling or file transfer handling. The server slot that handles new connections currently connects various signals from each socket instance that joins the server upon login (signals for such things as user joined, user logged off, etc) My question is how would I selectively emit a signal to only specific object instances that are connected as opposed to all of them? If someone sends a private message and there's multile connections, I obviously don't want the server sending everyone that message.
How do you categorize them as private message ? How do you identify which are the private clients. You need to apply these two filtering criteria on your own to incoming data. I'm not sure about your internal stuff.
What I can suggest you based is that try subclass QTcpServer and implement incomingConnection(...). This may help you.
Well, the format of the packets that are sent and received usually contain user ID of the recipient and what not. The thing is, would every connected socket need to parse that packet for a user ID match? Seems like an unnecessary use of signal handling, even if a thread pool is used. Or is that how it's meant to be?
Ah wait, I figured it out. QObject is the holy grail of problem solving
You need to maintain a list at server side using container like QSet for storing client socket ids for all clients.
and maintain another list using QMap for socket id and client id.
Hope it helps.
Yeah, I got it nailed. As I said, sender() was what I needed that I apparently overlooked.