TCP Client static port
-
Hi, I can connect to TCP server but I want to give spesific port number to client.
REMOTE_PORT = 5001; _client->connectToHost(REMOTE_ADDRESS, REMOTE_PORT);
remote port number is 5001 and I can connect it. But every time my port number is change.
How can I set spesefic port number to my client ? -
@Joe-von-Habsburg
Before answering this, why do you want to pick a specific port number at client side or care about what "random" port number TCP will pick for it without you doing so? Usually one does not, server specifies a port, clients connect using some local free port and that's all good. Yes, the client side port number will likely change each time, again that's fine. -
@Joe-von-Habsburg
You may be out luck, at least easily! Looks like I answered this in https://forum.qt.io/topic/100018/qtcpsocket-how-to-set-local-port in 2019!If it looks like further support was never added, I am suggesting those links are still valid and show you how you may achieve it from Qt.
There I suggested how it might be achieved with low-level calls, you could try.
Also perhaps https://gist.github.com/atomass/fadbc33039aa22991cfef1ea65ae9334
Most people who want to see traffic still manage without knowing client side port number, diagnostics show which server port it is connected to and you just work with that.
-