-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.cpp
54 lines (46 loc) · 1.34 KB
/
server.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "server.h"
#include <QDebug>
Server::Server(UVoipData* voipData, QObject *parent)
: QObject(parent)
, m_server()
, m_clientConnection()
, m_playback()
, m_voipData(voipData)
{
connect(&m_server, SIGNAL(newConnection()), this, SLOT(connectionHandler()));
connect(m_voipData, SIGNAL(requestDisconnectChanged()), this, SLOT(closeConnection()), Qt::DirectConnection);
m_server.listen(QHostAddress::Any, 1985);
}
void Server::connectionHandler()
{
m_clientConnection = m_server.nextPendingConnection();
connect(m_clientConnection, SIGNAL(disconnected()), this, SLOT(connectionClosed()), Qt::DirectConnection);
m_voipData->setServerConnected(true);
clientConnectionChanged();
}
void Server::clientConnectionChanged()
{
if(m_voipData->clientConnected() && m_clientConnection)
{
m_clientConnection->setSocketOption(QTcpSocket::LowDelayOption, 1);
m_playback.startPlaying(m_clientConnection);
qDebug() << "Server::clientConnected true";
}
else
{
closeConnection();
qDebug() << "Server::clientConnected false";
}
}
void Server::closeConnection()
{
// Checking since this could be a null pointer!
if(m_clientConnection)
{
m_clientConnection->close();
}
}
void Server::connectionClosed()
{
m_voipData->setServerConnected(false);
}