History

Rebind UDP socket when receiveHost/Port changed, jsdoc

Ada committed 10 months ago

Commit a4134b31 parent a29c9612 files · +113 −9Browse files

Showing the changes to interface/src/scripting/OSCScriptingInterface.cpp (1 of 2 files). Show all

Unified · Split

interface/src/scripting/OSCScriptingInterface.cpp+44−1
@@ -185,7 +185,7 @@ OSCScriptingInterface::OSCScriptingInterface(QObject* parent) : · 184 unmodified lines
185185
186186 connect(_socket.get(), &QUdpSocket::readyRead, this, &OSCScriptingInterface::readPacket);
187187
188− qCInfo(osc_cat) << "Listening on" << _socket->localAddress();
188+ qCInfo(osc_cat) << "Listening on" << _socket->localAddress() << ":" << _socket->localPort();
189189 }
190190
191191 OSCScriptingInterface::~OSCScriptingInterface() {
@@ -193,6 +193,11 @@ OSCScriptingInterface::~OSCScriptingInterface() { · 1 unmodified line
193193 qCInfo(osc_cat) << "Closed listen socket";
194194 }
195195
196+void OSCScriptingInterface::rebindSocket() {
197+ _socket->bind(QHostAddress(_sendHost.get()), _sendPort.get());
198+ qCInfo(osc_cat) << "Listening on" << _socket->localAddress() << ":" << _socket->localPort();
199+}
200+
196201 void OSCScriptingInterface::readPacket() {
197202 auto datagram = _socket->receiveDatagram();
198203
@@ -472,3 +477,41 @@ ScriptValue OSCScriptingInterface::sendPacket(ScriptContext* context, ScriptEngi · 273 unmodified lines
472477
473478 return engine->undefinedValue();
474479 }
480+
481+void OSCScriptingInterface::setReceiveHost(QString host) {
482+ QHostAddress address;
483+
484+ // only save if it's a valid address
485+ if (address.setAddress(host)) {
486+ _receiveHost.set(host);
487+ rebindSocket();
488+ }
489+}
490+
491+void OSCScriptingInterface::setSendHost(QString host) {
492+ QHostAddress address;
493+
494+ // only save if it's a valid address
495+ if (address.setAddress(host)) {
496+ _sendHost.set(host);
497+ }
498+}
499+
500+void OSCScriptingInterface::setSendPort(int port) {
501+ if (port < 1 || port > 65535) {
502+ qCritical(osc_cat) << "setSendPort: invalid port" << port;
503+ return;
504+ }
505+
506+ _sendPort.set(port);
507+}
508+
509+void OSCScriptingInterface::setReceivePort(int port) {
510+ if (port < 1024 || port > 65535) {
511+ qCritical(osc_cat) << "setReceivePort: invalid port" << port;
512+ return;
513+ }
514+
515+ _receivePort.set(port);
516+ rebindSocket();
517+}