Answer the question
In order to leave comments, you need to log in
Receiving data with QTcpSocket from server in python?
There was a problem getting data:
Server in python. Receives and processes data and sends the result:
def server(net, host, port):
sock = socket.socket()
sock.bind((host, port))
sock.listen(1)
print('Server start...')
while True:
c, addr = sock.accept()
print('Got connection from ', addr)
print('Receiving...')
f = open('pic', mode='wb')
rcvData = c.recv(BLOCK_SIZE)
f.write(rcvData)
while (rcvData):
print('Receiving...')
rcvData = c.recv(BLOCK_SIZE)
f.write(rcvData)
f.close()
print('Done receiving!')
img = cv2.imread('pic')
objLoc = getCaption(net, img)
print('processing is done')
writeObjLocToCsv(objLoc, 'objs')
z = open('objs', 'rb')
l = z.read(BLOCK_SIZE)
print(l)
print('send...')
print c.send(l)
c.close()
void Client::getCaption(QString &img)
{
pmSock = new QTcpSocket(this);
pmSock->connectToHost("127.0.0.1",12343);
sendQImage(img);
pmSock->waitForBytesWritten();
reciveData();
}
void Client::reciveData()
{
QString recvData;
//qDebug() << pmSock->waitForReadyRead(0);
qDebug() << "Reading: " << pmSock->bytesAvailable();//всегда 0
qDebug() << pmSock->readAll();
pmSock->close();
}
Answer the question
In order to leave comments, you need to log in
Because reciveData needs to be called when the data actually arrives.
those. bind to readyRead signal:
well, or put a check into an endless loop, but this is not according to Feng Shui.
And forget about
waitForBytesWritten();
waitForReadyRead()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question