forked from vranki/ExtPlane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcpserver.cpp
35 lines (30 loc) · 1.16 KB
/
tcpserver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "tcpserver.h"
#include "tcpclient.h"
#include "datarefprovider.h"
#include "util/console.h"
TcpServer::TcpServer(QObject *parent, DataRefProvider *refProvider) : QObject(parent), server(this), _refProvider(refProvider) {
if(!server.listen(QHostAddress::Any, EXTPLANE_PORT)) {
INFO << "Unable to listen on port " << EXTPLANE_PORT;
return;
}
connect(&server, SIGNAL(newConnection()), this, SLOT(clientConnected()));
INFO << "Listening on port " << EXTPLANE_PORT;
}
TcpServer::~TcpServer() {
DEBUG;
while (!clientConnections.isEmpty()) {
TcpClient *client = clientConnections.takeLast();
client->disconnect(this);
delete client;
}
}
void TcpServer::clientConnected() {
TcpClient *client = new TcpClient(this, server.nextPendingConnection(), _refProvider);
connect(client, SIGNAL(discoed(TcpClient *)), this, SLOT(clientDiscoed(TcpClient *)));
connect(client, SIGNAL(setFlightLoopInterval(float)), this, SIGNAL(setFlightLoopInterval(float)));
clientConnections.append(client);
}
void TcpServer::clientDiscoed(TcpClient *client) {
DEBUG << client;
clientConnections.removeOne(client);
}