I am looking at the examples. There is one that allows a client to receive data from the server.
Here, a signal is emitted every time new data is arriving:
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFortune()));
I have also done that in my server, but the method "readMessage()" is never called, have a look:
__________________________________________________ _______________
# include <QTcpSocket>
# include <iostream>
# include "client_thread.h"
ClientThread :: ClientThread(int socket_descriptor, QThread* parent) : QThread(parent)
{
std::cout << "Class ClientThread - Constructor\n";
this->socket_descriptor = socket_descriptor;
start();
}
void ClientThread :: run()
{
tcp_socket = new QTcpSocket();
connect(tcp_socket, SIGNAL(readyRead()), this, SLOT(readMessage()));
if(!tcp_socket->setSocketDescriptor(socket_descriptor))
{
std::cout << "Class ClientThread - Function run() - error setting socket descriptor\n";
return;
}
quint16* client_port;
client_port = new quint16(tcp_socket->peerPort());
std::cout << "Class ClientThread - Funcion run\n";
std::cout << "The client's port is: " << *client_port << "\n";
QByteArray* message = new QByteArray("Hello\n");
tcp_socket->write(*message);
tcp_socket->waitForBytesWritten(1000);
}
void ClientThread :: readMessage()
{
std::cout << "Class ClientThread - Function readMessage()\n";
}
_______________________________________________--
Help ?




Reply With Quote
Bookmarks