mirror of
https://github.com/ChronosX88/Influence-cjdns.git
synced 2024-11-23 07:32:19 +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()
|
||||
{
|
||||
network = new Network();
|
||||
network = new Network(false);
|
||||
connect(network, &Network::json_received, this, &Handler::handle);
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ void Handler::handle(QJsonObject jsonReceived)
|
||||
QJsonObject jsonSend;
|
||||
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["status"] = true;
|
||||
QString peerReceiver = jsonReceived["peerID"].toString();
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include "network.hpp"
|
||||
Network::Network()
|
||||
Network::Network(bool is_server)
|
||||
{
|
||||
udpSocket = new QUdpSocket(this);
|
||||
udpSocket->bind(QHostAddress::AnyIPv6, 6552);
|
||||
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processTheDatagram()));
|
||||
if (is_server)
|
||||
{
|
||||
udpSocket->bind(QHostAddress::AnyIPv6, 6552);
|
||||
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processTheDatagram()));
|
||||
}
|
||||
}
|
||||
|
||||
void Network::sendDatagram(QJsonObject j, QString s)
|
||||
|
@ -11,7 +11,7 @@ class Network : public QObject
|
||||
private:
|
||||
QUdpSocket* udpSocket;
|
||||
public:
|
||||
Network();
|
||||
Network(bool is_server = true);
|
||||
public slots:
|
||||
void sendDatagram(QJsonObject j, QString s);
|
||||
signals:
|
||||
|
@ -6,7 +6,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
network = new Network();
|
||||
network = new Network(true);
|
||||
handler = new Handler();
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ MainWindow::~MainWindow()
|
||||
void MainWindow::on_connectToPeer_clicked()
|
||||
{
|
||||
QJsonObject j;
|
||||
j["peerID"] = QHostAddress("::1").toString();
|
||||
j["peerID"] = QHostAddress("fc8f:cc50:70b0:3731:d686:a75e:94f2:f44f").toString();
|
||||
j["action"] = "createSession";
|
||||
QString s = ui->peerID->text();
|
||||
network->sendDatagram(j, s);
|
||||
|
Loading…
Reference in New Issue
Block a user