Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Extract from server.h */
- class Server : public QTcpServer
- {
- Q_OBJECT
- public:
- Server(QObject *parent = 0);
- virtual ~Server() { }
- private slots:
- void handleConnection();
- };
- /* Extract from server.cpp */
- Server::Server(QObject *parent) : QTcpServer(parent)
- {
- listen(QHostAddress::Any, 5555);
- connect(this, SIGNAL(newConnection()), SLOT(handleConnection()));
- }
- void Server::handleConnection()
- {
- QTcpSocket *socket = nextPendingConnection();
- forever {
- char buffer[1024];
- buffer[socket->read(buffer, 1023)] = 0;
- std::cout << buffer;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement