Windows 8.1 user here, using Qt 5.3. Trying to learn network programming (please bear with me). Let's say I have two network devices on my machine. One is assigned the IP 192.168.1.2, and the other 192.168.1.3. The first device has priority.
My goal is to create a QTcpServer on 192.168.1.2 and a QTcpSocket client on 192.168.1.3. The way I envision this would work is the data packets from the client will start at 192.168.1.3 (on some port), travel to the router, then to the server at 192.168.1.2 (on some port). Ok, hopefully this sounds reasonable.
Here's the problem. I can't find a functioning way to specify an outgoing address with QTcpSocket. There appears to be a bind method, but it doesn't do much. Each time I send that from the client, it travels on the default device at 192.168.1.2.
socket = new QTcpSocket(this);
qDebug() << socket->localAddress(); // shows "0"
qDebug() << socket->localPort(); // shows "0"
socket->bind(QHostAddress("192.168.1.3"), 50000);
qDebug() << socket->localAddress(); // shows "50000"
qDebug() << socket->localPort(); // shows "0"
//socket->setLocalAddress(QHostAddress("192.168.1.4")); // error, says it's protected
//socket->setLocalPort("50000"); // error, says it's protected
//qDebug() << socket->localAddress();
//qDebug() << socket->localPort();
socket->connectToHost("google.com", 80); // network manager shows data on 192.168.1.2
Any ideas?