Socket/server signal handling
-
wrote on 24 Jul 2014, 00:43 last edited by
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.
-
wrote on 24 Jul 2014, 01:02 last edited by
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?
-
wrote on 24 Jul 2014, 01:28 last edited by
Ah wait, I figured it out. QObject is the holy grail of problem solving
-
wrote on 24 Jul 2014, 07:23 last edited by
Hii.
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.
-
wrote on 25 Jul 2014, 18:29 last edited by
Yeah, I got it nailed. As I said, sender() was what I needed that I apparently overlooked.
1/6