[Interest] QUdpSpcket connection between two public peers behind firewalls

Nuno Santos nunosantos at imaginando.pt
Mon Dec 18 10:55:49 CET 2017


Hi,

I’m trying to establish a QUdpSocket connection between two peers that are behind firewalls. 

From what I have been reading, one way of doing this is recurring to a STUN Server, performing a bind request which will have as response our public IP and a port and not closing the socket.

Then, using the same socket, read data from it but from my experiments I’m never able to receive data on that socket sent by the other peer. Works locally but never publicly!

I don’t know what I’m doing wrong or how to debug. What am I missing here? 

Thanks!

Regards,

Nuno


// server

uint8_t tsx_id[12] = { 1 };
stun::message msg(stun::message::binding_request, tsx_id);

_socket = new QUdpSocket(this);
_socket->bind(3800); // binds socket without host specified
_socket->writeDatagram((char*) msg.data(), msg.size(), QHostAddress("66.102.1.127"), 19302); // sends binding request to stun server

...

stun::message reply;
reply.resize(2*1024);

 _socket->readDatagram((char*) reply.data(), reply.capacity(), &host, &port); // receives reply from stun server with public address and port, e.g.: “X.Y.Z.W” port 3800

...

int data=0;
_socket->readDatagram((char*) &data, sizeof(int)) << data; // reads data from socket but nothing comes in

// client

static int data=0;
int port=3800
QHostAddress host("X.Y.Z.W");

_socket = new QUdpSocket(this);
_socket->writeDatagram(QString(data).toUtf8(), host, port) << data++; // successfully writes data to public IP and port of the peer 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20171218/6af731c3/attachment.html>


More information about the Interest mailing list