qtcpsocket

QTcpSocket state always connected, even unplugging ethernet wire

痞子三分冷 提交于 2019-11-28 04:43:20
I have a QTcpSocket and I am reading into a loop. Each time a full packet has been read, or there has been an error, I manually check the status of the socket inside the loop, with: while(true){ if(socket->state()==QAbstractSocket::ConnectedState){ qDebug()<<"Socket status: connected. Looking for packets..."; if(socket->waitForReadyRead(2000)){ //... } When I execute de program, once connected and the loop starts, it always prints qDebug()<<"Socket status: connected. Looking for packets..." ; and then stucks at waitForReadyRead until some data is ready to be read. The problem is that

Qt, Sending multiple data types from client to server + data Streaming

只愿长相守 提交于 2019-11-28 02:31:50
问题 I have a Client/Server based Qt application, using QTcpServer and QTcpSocket, I managed to do the connection and send some data back and forth between the client and the server. The client sends many types of data to the server (string, int, files and a real time audio stream) and since my server impliment a single data input SLOT (readyRead()): connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead())); I don't know how could I distinguish between all this received data and call

Read from QTcpSocket using QDataStream

感情迁移 提交于 2019-11-27 09:17:27
I need to send binary data through a QTcpSocket . I was thinking about using QDataStream , but I've encountered a problem - it silently fails if no data has arrived at the time I try to read. For example if I have this code: QString str; stream >> str; It will fail silently if no data is currently there in the socket. Is there a way to tell it to block instead? The problem is a bit more serious. Socket can receive data in chunks, so even if you will wait for waitForReadyRead it can fail since there is not enough data to immediately read some object. To solve this problem you have to send a

How to use QTcpSocket instance multiple times with couple second intervals?

℡╲_俬逩灬. 提交于 2019-11-27 07:31:36
问题 I have to repeat the same request with QTcpSocket multiple times with a couple seconds intervals. Easy task but I can't get it to work with only one instance of object. How to connect to server again using the same instance of QTcpSocket? I've tried reset(), resume(), flush(), open() in many diffrent combinations and it has done nothing. I'm unable to connectToHost() for second time... 回答1: All you have to do is to connectToHost() , use the connection, then disconnectFromHost() . That's it.

QTcpSocket state always connected, even unplugging ethernet wire

谁说我不能喝 提交于 2019-11-27 00:29:42
问题 I have a QTcpSocket and I am reading into a loop. Each time a full packet has been read, or there has been an error, I manually check the status of the socket inside the loop, with: while(true){ if(socket->state()==QAbstractSocket::ConnectedState){ qDebug()<<"Socket status: connected. Looking for packets..."; if(socket->waitForReadyRead(2000)){ //... } When I execute de program, once connected and the loop starts, it always prints qDebug()<<"Socket status: connected. Looking for packets..." ;

Read from QTcpSocket using QDataStream

北城余情 提交于 2019-11-26 17:48:45
问题 I need to send binary data through a QTcpSocket . I was thinking about using QDataStream , but I've encountered a problem - it silently fails if no data has arrived at the time I try to read. For example if I have this code: QString str; stream >> str; It will fail silently if no data is currently there in the socket. Is there a way to tell it to block instead? 回答1: The problem is a bit more serious. Socket can receive data in chunks, so even if you will wait for waitForReadyRead it can fail