[Interest] QUdpSpcket connection between two public peers behind firewalls

Thiago Macieira thiago.macieira at intel.com
Mon Dec 18 17:25:25 CET 2017


On Monday, 18 December 2017 01:55:49 PST Nuno Santos wrote:
> 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.

I don't know what a STUN server is. I'm going to assume it's some kind of 
proxy that QUdpSocket does not support. The only type that it does support is 
SOCKS5, so if you have the option, use that.

Your explanation of how you assume it works is missing some information. 
That's what's causing the problem: you assume wrong. You need to perform more 
steps. Please consult your proxy server's protocol documentation for more.

> // 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

Ok, if you say so.

> ...
> 
> 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

Unrelated: you should use the receiveDatagram() function in new code.

> 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


-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list