Server is not reading from client
I have this very simple server and I would like it to be able to read any data from a client.
the .h file
**********************************
Code:
#ifndef CLIENTSERVER_H
#define CLIENTSERVER_H
#include <QMainWindow>
{
Q_OBJECT
private:
public:
ClientServer();
signals:
public slots:
void readData();
};
# endif
***************************************
the .cpp file
***************************************
Code:
#include <QTextBrowser>
#include <QByteArray>
#include <QTcpSocket>
#include <QTcpServer>
#include "clientserver.h"
ClientServer::ClientServer()
{
setCentralWidget(textBrowser);
setFixedSize(500,500);
show();
if(tcpServer
->listen
(QHostAddress("localhost"), quint16
(33333))) textBrowser->append("ClientServer is listening");
tcpSocket->setSocketDescriptor(tcpServer->socketDescriptor());
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
}
void ClientServer::readData()
{
textBrowser->append("Ready to read");
}
************************************************** ***
I cannot even get to the readData() function.
Why?
How can I make it read from a client?
Re: Server is not reading from client
You should connect to signal QTcpServer::newConnection() and then use QTcpServer::nextPendingConnection() to get the socket whose signal QTcpSocket::readyRead() you are interested of. See the examples shipped with Qt or the Simple Chat example in our wiki.
Re: Server is not reading from client
I read now from the client (browser), but I cannot write to the browser. When I write to a telnet window, then the message is shown there, but the browser does not display the html message.
How can I solve it ?
Re: Server is not reading from client
I don't want to make my code to complex...
I just want to know:
1. How can the server know that the browser has finished sending all its data ?
Re: Server is not reading from client
You don't know unless you provide some kind of "end-of-message" mark from the other side. Read this thread.