QTcpSocket and specifying an outgoing network device client

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. Each is assigned an 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 assume this will work is data packets from the client starting at 192.168.1.3 (on some port), going to the router and then to the server at 192.168.1.2 (on some port) ... Okay, I hope this sounds reasonable.

Here's the problem. I cannot find a way to determine the outgoing address with QTcpSocket. There appears to be a binding method, but it doesn't do much. Every time I post this from a client, it moves to 192.168.1.2 by default.

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 protected
//socket->setLocalPort("50000"); // error, says it protected
//qDebug() << socket->localAddress();
//qDebug() << socket->localPort();

socket->connectToHost("google.com", 80); // network manager shows data on 192.168.1.2

      

Any ideas?

+3
c ++ qt qt5 tcp tcpserver


source to share


No one has answered this question yet

Check out similar questions:

345
What is the maximum TCP / IP network port number allowed for IPv4?
nine
Qt bi-directional client server using QTcpSocket and QTcpServer
five
How can I read complete data into a QTcpSocket?
4
QTcpSocket client auto reconnect
3
QTcpSocket - Invalid handle was specified in QRunnable output
1
QTcpSocket and deletion
1
Network connections in OpenShift
0
Using QTcpSockets across different threads
0
Multithreaded TCP client using QTcpSocket
-1
QTcpSocket descriptor error



All Articles
Loading...
X
Show
Funny
Dev
Pics