QTcpSocket and QUdpSocket on Windows 10, blocked?
-
Last week I wrote an application using both QTcpSocket and QUdpSocket, both worked without issues, today I started the PC and I'm not aware of any changes that have been made, also I'm wasn't aware of any dialog or prompts, however I have previous experience where on Windows 10 the sockets stop working because of the firewall.
Is there a dialog or something I can use to resolve this problem as right now I cannot get the application to communicate. To be clear, I have two applications both using QTcpSocket and QUdpSocket, QUdpSocket is used to broadcast a heartbeat.
There is no activity, nothing is being received the WriteDatagram method returns correctly the number of bytes written to the socket.
-
@KroMignon , @jsulm , ok, I've changed the port to 30119 for UDP communications, which seems to work on one application, on the other application that is going to receive the broadcasts and act on them I'm getting:
Failed to bind UDP socket: The bound address is already in useBoth applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
Both applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?
Do you want to bind each socket on same port?
So you have allow reusing same port:if(!pUDPsocket->bind(QHostAddress::LocalHost, 8124, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint)) { qWarn() << "Failed to bind UDP socket:" << pUDPsocket->errorString(); } -
If you can run wireshark then you can sniff the traffic to see if the packets are at least getting out of the program.
-
@Kent-Dorfman , thank you, downloaded and installed on the laptop, here is a screenshot.

Not sure what I'm supposed to do now, I've tried the WiFi and I'm not seeing anything that resembles the content I'm sending. Since the function returns a positive value indicating that It has succeeded, what else can I do? -
@Kent-Dorfman , thank you, downloaded and installed on the laptop, here is a screenshot.

Not sure what I'm supposed to do now, I've tried the WiFi and I'm not seeing anything that resembles the content I'm sending. Since the function returns a positive value indicating that It has succeeded, what else can I do?@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
Since the function returns a positive value indicating that It has succeeded, what else can I do?
That's not totally true, positive return value only indicates that message has been "accepted" by TCP/IP stack, that's all.
Where are receiver and sender located? on same machine?
Are you sure you are using right network support?
Do you have multiple possible routes between receiver and sender?For WireShark you can start an listening for the UDP port you are using for your "heartbeat" signal. In filter simply enter "upd port xxx" where xxx is the port number (cf https://wiki.wireshark.org/CaptureFilters for more details).
-
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
Since the function returns a positive value indicating that It has succeeded, what else can I do?
That's not totally true, positive return value only indicates that message has been "accepted" by TCP/IP stack, that's all.
Where are receiver and sender located? on same machine?
Are you sure you are using right network support?
Do you have multiple possible routes between receiver and sender?For WireShark you can start an listening for the UDP port you are using for your "heartbeat" signal. In filter simply enter "upd port xxx" where xxx is the port number (cf https://wiki.wireshark.org/CaptureFilters for more details).
@KroMignon , yes, presently both the sender and receiving applications are running on the same laptop.
The problem I'm having is the laptop is so locked down by the company IT that I'm not sure if it is causing problems, as I said, last week these same applications were communicating.
I will try capturing data on WireShark for the UDP port.
I've just added filter to WireShark:
udp.port eq 81248124 is the port I'm using to broadcast on, I've also modified my source to:
writeDatagram(bytaryDoc, QHostAddress::Broadcast, suint16Port);Seeing nothing in WireShark.
-
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
Since the function returns a positive value indicating that It has succeeded, what else can I do?
That's not totally true, positive return value only indicates that message has been "accepted" by TCP/IP stack, that's all.
Where are receiver and sender located? on same machine?
Are you sure you are using right network support?
Do you have multiple possible routes between receiver and sender?For WireShark you can start an listening for the UDP port you are using for your "heartbeat" signal. In filter simply enter "upd port xxx" where xxx is the port number (cf https://wiki.wireshark.org/CaptureFilters for more details).
@KroMignon , I'm now seeing the packet broadcast on WireShark, not receiving it on the other application.
-
@KroMignon , I'm now seeing the packet broadcast on WireShark, not receiving it on the other application.
-
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
not receiving it on the other application.
On which port+ip have you bind you udp socket?
@KroMignon , the IT department has just unlocked the app in the firewall...hopefully now it will work.
-
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
not receiving it on the other application.
On which port+ip have you bind you udp socket?
@KroMignon , IT unlocked the firewall, I can see that the application that is broadcasting a packet using UDP is appearing on WireShark, but I am still not receiving the packet in the other application which has been unblocked in the firewall.
The connection source for this application:
pUDPsocket = new QUdpSocket(this); pUDPsocket->bind(QHostAddress::LocalHost, 8124); QObject::connect(pUDPsocket, &QUdpSocket::readyRead, this, &SckServer::udpRead);My slot:
void SckServer::udpRead() { while( pUDPsocket->hasPendingDatagrams() ) { QNetworkDatagram datagram(pUDPsocket->receiveDatagram()); ... } }It never gets into udpRead... The IP address resolves to 10.132.55.189 and the port is 8124.
-
@KroMignon , IT unlocked the firewall, I can see that the application that is broadcasting a packet using UDP is appearing on WireShark, but I am still not receiving the packet in the other application which has been unblocked in the firewall.
The connection source for this application:
pUDPsocket = new QUdpSocket(this); pUDPsocket->bind(QHostAddress::LocalHost, 8124); QObject::connect(pUDPsocket, &QUdpSocket::readyRead, this, &SckServer::udpRead);My slot:
void SckServer::udpRead() { while( pUDPsocket->hasPendingDatagrams() ) { QNetworkDatagram datagram(pUDPsocket->receiveDatagram()); ... } }It never gets into udpRead... The IP address resolves to 10.132.55.189 and the port is 8124.
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
pUDPsocket->bind(QHostAddress::LocalHost, 8124);
You should verify that bind did work:
if(!pUDPsocket->bind(QHostAddress::LocalHost, 8124)) { qWarn() << "Failed to bind UDP socket:" << pUDPsocket->errorString(); } -
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
pUDPsocket->bind(QHostAddress::LocalHost, 8124);
You should verify that bind did work:
if(!pUDPsocket->bind(QHostAddress::LocalHost, 8124)) { qWarn() << "Failed to bind UDP socket:" << pUDPsocket->errorString(); }@KroMignon , thank you, interesting the bind is failing:
Failed to bind UDP socket: The address is protected. -
@KroMignon , thank you, interesting the bind is failing:
Failed to bind UDP socket: The address is protected. -
@jsulm , I was just looking at:
https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_portsWhats preventing me choosing a port that is in use for something else? For example 13?
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
Whats preventing me choosing a port that is in use for something else? For example 13?
As already written by @jsulm , port numbers bellow 1000 are reserved for system. You need to have root rights to bind on them.
This is called security ;) -
@jsulm , I was just looking at:
https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_portsWhats preventing me choosing a port that is in use for something else? For example 13?
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
Whats preventing me choosing a port that is in use for something else?
From the link you posted (and what I wrote before): "On Unix-like operating systems, a process must execute with superuser privileges to be able to bind a network socket to an IP address using one of the well-known ports."
-
@KroMignon , @jsulm , ok, I've changed the port to 30119 for UDP communications, which seems to work on one application, on the other application that is going to receive the broadcasts and act on them I'm getting:
Failed to bind UDP socket: The bound address is already in useBoth applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?
-
@KroMignon , @jsulm , ok, I've changed the port to 30119 for UDP communications, which seems to work on one application, on the other application that is going to receive the broadcasts and act on them I'm getting:
Failed to bind UDP socket: The bound address is already in useBoth applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
Both applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?
Do you want to bind each socket on same port?
So you have allow reusing same port:if(!pUDPsocket->bind(QHostAddress::LocalHost, 8124, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint)) { qWarn() << "Failed to bind UDP socket:" << pUDPsocket->errorString(); } -
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
Both applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?
Do you want to bind each socket on same port?
So you have allow reusing same port:if(!pUDPsocket->bind(QHostAddress::LocalHost, 8124, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint)) { qWarn() << "Failed to bind UDP socket:" << pUDPsocket->errorString(); }@KroMignon , thank you, I literally just added exactly that, compiling now and will try.
-
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
Both applications are running on the same laptop, how do I set-up the receiver so it can receive messages broadcast on the same IP and port 30119 ?
Do you want to bind each socket on same port?
So you have allow reusing same port:if(!pUDPsocket->bind(QHostAddress::LocalHost, 8124, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint)) { qWarn() << "Failed to bind UDP socket:" << pUDPsocket->errorString(); }@KroMignon , its working :)
-
@KroMignon , yes, presently both the sender and receiving applications are running on the same laptop.
The problem I'm having is the laptop is so locked down by the company IT that I'm not sure if it is causing problems, as I said, last week these same applications were communicating.
I will try capturing data on WireShark for the UDP port.
I've just added filter to WireShark:
udp.port eq 81248124 is the port I'm using to broadcast on, I've also modified my source to:
writeDatagram(bytaryDoc, QHostAddress::Broadcast, suint16Port);Seeing nothing in WireShark.
@SPlatten said in QTcpSocket and QUdpSocket on Windows 10, blocked?:
The problem I'm having is the laptop is so locked down by the company IT that I'm not sure if it is causing problems, as I said, last week these same applications were communicating.
And therein is the problem...and it ticks me off to no end. If you cannot own and control your dev resources then you're just whizzin in the wind when you need to do real work. These dumb-acre kids who think they know and understand network security need to be taken to the wood shed and whipped with a willow switch when they start treating devs like office admin workers.