mirror of
https://github.com/ChronosX88/Influence-cjdns.git
synced 2024-11-23 15:42:18 +00:00
Changed the Network class constructor
Now sockets do not overlap (if you create an object of class Network in some other class).
This commit is contained in:
parent
7fa9deb1d4
commit
a2fee2fe26
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Handler::Handler()
|
Handler::Handler()
|
||||||
{
|
{
|
||||||
network = new Network();
|
network = new Network(false);
|
||||||
connect(network, &Network::json_received, this, &Handler::handle);
|
connect(network, &Network::json_received, this, &Handler::handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ void Handler::handle(QJsonObject jsonReceived)
|
|||||||
QJsonObject jsonSend;
|
QJsonObject jsonSend;
|
||||||
if(jsonReceived["action"] == "createSession" && !jsonReceived.contains("status"))
|
if(jsonReceived["action"] == "createSession" && !jsonReceived.contains("status"))
|
||||||
{
|
{
|
||||||
jsonSend["peerID"] = QHostAddress("::1").toString();
|
jsonSend["peerID"] = QHostAddress("fc8f:cc50:70b0:3731:d686:a75e:94f2:f44f").toString();
|
||||||
jsonSend["action"] = "createSession";
|
jsonSend["action"] = "createSession";
|
||||||
jsonSend["status"] = true;
|
jsonSend["status"] = true;
|
||||||
QString peerReceiver = jsonReceived["peerID"].toString();
|
QString peerReceiver = jsonReceived["peerID"].toString();
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#include "network.hpp"
|
#include "network.hpp"
|
||||||
Network::Network()
|
Network::Network(bool is_server)
|
||||||
{
|
{
|
||||||
udpSocket = new QUdpSocket(this);
|
udpSocket = new QUdpSocket(this);
|
||||||
udpSocket->bind(QHostAddress::AnyIPv6, 6552);
|
if (is_server)
|
||||||
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processTheDatagram()));
|
{
|
||||||
|
udpSocket->bind(QHostAddress::AnyIPv6, 6552);
|
||||||
|
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processTheDatagram()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::sendDatagram(QJsonObject j, QString s)
|
void Network::sendDatagram(QJsonObject j, QString s)
|
||||||
|
@ -11,7 +11,7 @@ class Network : public QObject
|
|||||||
private:
|
private:
|
||||||
QUdpSocket* udpSocket;
|
QUdpSocket* udpSocket;
|
||||||
public:
|
public:
|
||||||
Network();
|
Network(bool is_server = true);
|
||||||
public slots:
|
public slots:
|
||||||
void sendDatagram(QJsonObject j, QString s);
|
void sendDatagram(QJsonObject j, QString s);
|
||||||
signals:
|
signals:
|
||||||
|
@ -6,7 +6,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui(new Ui::MainWindow)
|
ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
network = new Network();
|
network = new Network(true);
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ MainWindow::~MainWindow()
|
|||||||
void MainWindow::on_connectToPeer_clicked()
|
void MainWindow::on_connectToPeer_clicked()
|
||||||
{
|
{
|
||||||
QJsonObject j;
|
QJsonObject j;
|
||||||
j["peerID"] = QHostAddress("::1").toString();
|
j["peerID"] = QHostAddress("fc8f:cc50:70b0:3731:d686:a75e:94f2:f44f").toString();
|
||||||
j["action"] = "createSession";
|
j["action"] = "createSession";
|
||||||
QString s = ui->peerID->text();
|
QString s = ui->peerID->text();
|
||||||
network->sendDatagram(j, s);
|
network->sendDatagram(j, s);
|
||||||
|
Loading…
Reference in New Issue
Block a user