qtcpsocket


PyQt5: Sending and receiving messages between client and server

∥☆過路亽.° 提交于 2020-01-01 19:27:17
问题 I am trying to create a server and client to send and receive messages. My problem is to send and receive between the client and the server. client.py : from PyQt5.QtCore import QIODevice from PyQt5.QtWidgets import QApplication, QDialog from PyQt5.QtNetwork import QTcpSocket class Client(QDialog): def __init__(self): super().__init__() HOST = '127.0.0.1' PORT = 8000 self.tcpSocket = QTcpSocket(self) self.tcpSocket.connectToHost(HOST, PORT, QIODevice.ReadWrite) self.tcpSocket.readyRead

How to read complete data in QTcpSocket?

纵饮孤独 提交于 2019-12-29 07:42:09
问题 Now the server (implemented with java) will send some stream data to me, my code is like below: connect(socket, SIGNAL(readyRead()), this, SLOT(read_from_server())); in the read_from_server() : { while (socket->bytesAvailable()) { QString temp = socket->readAll(); } } but I find that even the server sent me a string with only several characters, the data is truncated, and my function is called twice, thus temp is the never complete data that I want. If server send me a longer string, my

Is the QTcpSocket (or QSslSocket) which underlies a QWebSocket — destroyed by itself when a socket error happens?

混江龙づ霸主 提交于 2019-12-23 18:17:40
问题 When a QTcpSocket (or QSslSocket ) is upgraded to a QWebSocket , the former has to be stored for the future purpose, as it requires to be ... moved to the same thread wherever QWebSocket is being moveToThread() deleteLater() whenever QWebSocket is being destroyed Failing to do 1. results in undefined behaviour and most likely a crash. While failing to do 2. results in a memory leak, which is more prominent if you are having a QWebSocketServer (QWebSocketServer - not releasing memory). I

QTcpSocket connecting results in UnknownSocketError with errorString “UnknownError”

半腔热情 提交于 2019-12-12 03:49:03
问题 Problem I am unable to get any further information regarding this error: QAbstractSocket::UnknownSocketError The QT QAbstractSocket::SocketError provides only a basic explanation that some error has occurred An unidentified error occurred. enum value = -1 Calling QTcpSocket::errorString() provides this: "Unknown error" There is one question regarding this here on SO but provides no real solution to solving the issue (and what was suggested I have done) I have absoltely no idea how to further

Pyqt ; QTcpSocket always in connectingState after server restart;

≯℡__Kan透↙ 提交于 2019-12-11 08:18:42
问题 I've got a subclass of QTcpSocket. And problem is : when i firt time connect to server - everything ok, but after socket connected i restart server (python socketServer,just close and start script again) socket disconnecting and tryin to reconnect while server is down, but when i start server again - nothing happened, socket.state() always in ConnectingState.. what is wrong ? Here example code: # -*- coding: utf-8 -*- from PyQt4.QtCore import QVariant, QTimer, pyqtSignal, QCoreApplication

How to write on multiple QTcpSockets using QThreads?

微笑、不失礼 提交于 2019-12-11 05:49:07
问题 I've been struggling for a couple of days now with this problem on QTcpSockets and QThreads. I have a QTcpServer that listens on a port and creates a new Client using the nextPendingConnection(). So now the client has a qtcpsocket which I can use for reading and writing. Let's suppose I have 100 clients connected to my server. When one of them wants to broadcast a message to everybody, my main thread (where I create the clients with nextPendingConnection() ) will have to iterate over 100

Why can't my code read the number of bytes available on a QTcpSocket? Ideas?

人盡茶涼 提交于 2019-12-11 01:59:49
问题 I have the following snippet of code in the body of a loop responsible for reading data from a QTcpSocket (nntp is a pointer to a QTcpSocket). std::vector<char> buffer; int bytesAvailable = nntp->bytesAvailable(); qDebug() << "bytesAvailable: "<<bytesAvailable; if(bytesAvailable <= 0) break; buffer.resize(bytesAvailable); bytesRead = nntp->read(&buffer[0], bytesAvailable); qDebug() << (nntp->state() == QAbstractSocket::ConnectedState); qDebug() << "bytesRead: "<<bytesRead; Intermittently,

Get remote host Ip address QTcpServer

两盒软妹~` 提交于 2019-12-10 13:20:12
问题 I'm using Qt to create TCP server using QTcpServer. Every time a client connects to server, I would like to know the remote host's IP address and port number. I tried searching documentation but couldn't find any information on this topic. I know there should be a way, I'm just not able to figure it out. Help please. 回答1: QTcpServer won't tell you the address/port directly on an incoming connection but you can get it by getting the connected QTcpSocket from QTcpServer::nextPendingConnection()

Qt/C++ QTcpSocket causes memory leak, not sure why

别来无恙 提交于 2019-12-10 12:17:21
问题 I am creating a simple(ish) telnet server and am now debugging with valgrind. the code runs great, but valgrind complains about memory lost when the program terminates...and the culprit is the line where I create a new QTcpSocket: void TelnetConnection::run() { tcpSocketPtr = new QTcpSocket(); // ** remove this due to parent error if (!tcpSocketPtr->setSocketDescriptor(socketDescriptor)) { emit error(tcpSocketPtr->error()); return; } } I tried passing 'this' to the QTcpSocket() but then the

QTcpSocket receiving transfer

假如想象 提交于 2019-12-08 05:59:31
问题 I'm having issues with receiving a transfer. QTcpSocket->readAll() does not read enough bytes when I'm sending to it. When I send 15k bytes, it reads only some part of it and then does nothing. What am I doing wrong? QByteArray array; array = socket->readAll(); //just reads some part, not fully. Why does this happen? 回答1: Most probably the socket didn't receive all data yet when you call readAll() . This is because of TCP communication happens in small packets (each having around 1KB of data,

工具导航Map