Hello. I will explain the essence of the problem. In general, I have a task - to connect to the server. This server will return to me the IP and PORT server for authorization. That is, then I need to connect to the read server for authorization. Of course, you can simply disconnect from the first server and connect to another, but what about the signals and slots? After all, they will be sharpened only for one of the servers. Please explain how to do what I want.

  • Do you feel sorry for sockets? Create 1 more - Alex Kapustin
  • As far as I know TCP (in * nix) an already-socket socket cannot be reused in another connection. If the connection no longer needs to close the socket. - avp
  • @avp And where can I reuse an already connected socket? - alexlz
  • @Leha Emelianenko I don’t know qt, but I suspect that a number of terms in question are from there. Only it is difficult for me to imagine a library that would limit the programmer so much. You can create another socket without closing the current one. HTTP connections are supported by cookies, so you will have to be puzzled by their receipt / transmission. If you are concerned about how to synchronize work with multiple connections, this is another question. Qt seems to have its own (defacto standard) mechanisms - alexlz
  • one
    And in other systems, it is modeled on * nix, since it implements the same protocols. (Remember select in winsocket) - alexlz

1 answer 1

Smoke examples, docks. Max Schlee in the end. And you will immediately understand everything. If you stumble on such simple questions, then what will happen next.


With signals and slots, nothing will happen. Simply unplug the socket from the server and from the signals when the transfer is complete.

void QLoader::onDisconnectFromServer(){ tcpSocket->disconnectFromHost(); tcpSocket->disconnect(this); } 

Process data and connect to another server.

 tcpSocket->connectToHost(IP, PORT); connect(tcpSocket, SIGNAL(connected()),this, SLOT(onConnected())); connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(onDisconnected())); connect(tcpSocket, SIGNAL(readyRead()),this, SLOT(onReadyRead())); connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError))); connect (tcpSocket, SIGNAL(readChannelFinished(), this, SLOT(onFinished())); 

Wrap it in class and you will be happy.

  • Worthy answer kR00togo xAckErA. And what is Max Schlee? I also want everything to be clear to me. - alexlz
  • This is the author of a very good book on Qt. ozon.ru/context/detail/id/4777403 - ReklatsMasters
  • Yes, the answer is good. The bottom line: I do not know myself, but I heard that there are cool books ... (then offers to purchase it for 989.00 rubles in Ozone). At the same time, it is stated that the question is simple. - avp
  • Well, in the internet, the book is in the files. True, I do not know how legal it is to download it from there. And in the modern Criminal Code there are very interesting articles - alexlz
  • @alexlz, and the book is worth it? Or poltysch pages for beginners plus the text of all the man-s on the topic? - avp