...
Code Block |
---|
#include "tcp_server.h" TCPServer::TCPServer() { server = new QxtRPCPeer(); serverIp = QHostAddress::Any; serverPort = 45123; qRegisterMetaTypeStreamOperators< QVector<QString> >("QVector<QString>"); server->attachSlot(QString("signal1"), this, SLOT(receiveSignal(quint64, QVector<QString>))); connect(this->server, SIGNAL(clientConnected(quint64)), this, SLOT(newClient(quint64))); connect(this->server, SIGNAL(clientDisconnected(quint64)), this, SLOT(deleteClient(quint64))); } TCPServer::~TCPServer() { delete server; } void TCPServer::startServer() { server->listen(this->serverIp, this->serverPort); qDebug() << "server up"; } void TCPServer::startServer(QHostAddress address, int port) { server->listen(address, port); qDebug() << "server up"; } void TCPServer::stopServer() { server->stopListening(); clients.empty(); qDebug() << "server down"; } void TCPServer::newClient(quint64 clientId) { clients.append(clientId); qDebug() << clientId << " connected"; } void TCPServer::deleteClient(quint64 clientId) { int delClient = clients.indexOf(clientId); clients.removeAt(delClient); qDebug() << clientId << " disconnected"; } void TCPServer::receiveSignal(quint64 connectionId, QVector<QString> data) { // Tee jotain data:lle } |
...