Hello Everybody
I would like to make a client-server arcitecture with Qt 4.0, using QTcpServer and QTcpSocket. I want one server and several, say 10 clients. I also want to communicate in both directions, sending messages from server to clients (which is easy) and from clients to servers (that's the hard part).
I tried to do it in the following way. I have a QTcpServer listening on one machine's port. I have several clients on other machines or port. First they all try to connect the server through the given hostname and port using connectToHost(). In the server whenever a new connection arrives I put the result of nextPendingConnection() to a vector containing sockets. Now this way it is easy to send anything to the clients from the server, I simply choose a socket from that vector and than send something on that socket (using QDataStream on the choosen socket, than write).
However, I can't see how can I send anything from the clients to the server. I use the client's socket to send some data. When data arrives in the server a readyRead() signal is emitted. But how can I know which socket emitted that signal? How can I choose the right socket from my vector? I cannot even send an ID with the client, because for reading that ID the server should first know which client sent that ID. So is there any solution, or my whole arcithecture is wrong this way? If it is wrong, could you sketch some other way.
ps. I saw that there was many thread about similar questions, but I could not find a satisfying answer anywhere, if You know about one I'm glad if you point to it.
Thanks for Your answers
Peter
Bookmarks