-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipcinterface.cpp
62 lines (53 loc) · 2.05 KB
/
ipcinterface.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
55
56
57
58
59
60
61
62
/************************************************************************************************
Kioo Media Player: A Player With Clear Crystal Sound, Extra Sharp Video, with a Beautiful Design.
Copyright (C) 2017 - 2020 Kioo Media Player <[email protected]>.
Homepage: https://www.kiooplayer.com
Developer: Godfrey E Laswai <[email protected]>
All rights reserved.
Use of this source code is governed by a BSD-3-Clause license that can be
found in the BSD-LICENSE file or see it here <https://opensource.org/licenses/BSD-3-Clause>.
*************************************************************************************************/
#include "ipcinterface.h"
IPCInterface::IPCInterface(QObject *parent) : QObject(parent)
{
this->tcpServer = new QTcpServer();
connect(tcpServer,SIGNAL(newConnection()),this,SLOT(newConnection()));
if(!tcpServer->listen(QHostAddress::LocalHost,9898)) {
// qDebug() << "Failed to listen to local port";
}
}
IPCInterface::~IPCInterface()
{
delete tcpClient;
delete tcpServer;
delete tcpServerConnection;
}
void IPCInterface::clientConnect()
{
// qDebug() << "Connecting to server";
this->tcpClient = new QTcpSocket();
connect(tcpClient,SIGNAL(connected()),this,SLOT(clientReadyWrite()));
tcpClient->connectToHost(QHostAddress::LocalHost,9898);
if(!tcpClient->waitForConnected(2000)){
// qDebug() << "Failed to connected";
// dataSent = true;
}
return;
}
void IPCInterface::newConnection()
{
this->tcpServerConnection = tcpServer->nextPendingConnection();
connect(tcpServerConnection,SIGNAL(readyRead()),this,SLOT(serverReadyRead()));
}
void IPCInterface::serverReadyRead()
{
QString str = QString(tcpServerConnection->readLine());
emit linkReceived(str);
}
void IPCInterface::clientReadyWrite()
{
// qDebug() << "Connected to server, sending data..";
tcpClient->write(ipcPayload.toUtf8());
tcpClient->waitForBytesWritten(2000);
this->dataSent = true;
}