probine
30th November 2006, 14:21
I have this very simple server and I would like it to be able to read any data from a client.
the .h file
**********************************
#ifndef CLIENTSERVER_H
#define CLIENTSERVER_H
#include <QMainWindow>
class QTextBrowser;
class QByteArray;
class QTcpSocket;
class QTcpServer;
class ClientServer : public QMainWindow
{
Q_OBJECT
private:
QTextBrowser * textBrowser;
QByteArray * byteArray;
QTcpSocket * tcpSocket;
QTcpServer * tcpServer;
public:
ClientServer();
signals:
public slots:
void readData();
};
# endif
***************************************
the .cpp file
***************************************
#include <QTextBrowser>
#include <QByteArray>
#include <QTcpSocket>
#include <QTcpServer>
#include "clientserver.h"
ClientServer::ClientServer()
{
textBrowser = new QTextBrowser(this);
tcpServer = new QTcpServer();
tcpSocket = new QTcpSocket();
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?
the .h file
**********************************
#ifndef CLIENTSERVER_H
#define CLIENTSERVER_H
#include <QMainWindow>
class QTextBrowser;
class QByteArray;
class QTcpSocket;
class QTcpServer;
class ClientServer : public QMainWindow
{
Q_OBJECT
private:
QTextBrowser * textBrowser;
QByteArray * byteArray;
QTcpSocket * tcpSocket;
QTcpServer * tcpServer;
public:
ClientServer();
signals:
public slots:
void readData();
};
# endif
***************************************
the .cpp file
***************************************
#include <QTextBrowser>
#include <QByteArray>
#include <QTcpSocket>
#include <QTcpServer>
#include "clientserver.h"
ClientServer::ClientServer()
{
textBrowser = new QTextBrowser(this);
tcpServer = new QTcpServer();
tcpSocket = new QTcpSocket();
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?