Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QAbstractSocket::SocketAccessError when trying to listen on a port



  • Using Windows 10 and Qt 4.7.4; On some machines, we sometimes get a QAbstractSocket::SocketAccessError error when using QTcpServer::listen. What are the possible causes of that error?

    No other process is using the port (verified using netstat, task manager, and currports), and it happens whether or not the application is run as administrator.

    We are using a port that is in the ephemeral port range (49152-65535); are there cases where Windows simply refuses to let an application use one of these ports to listen for incoming connections?

    When the issue occurs, only restarting the computer can fix the issue. This leads me to believe that it's not a firewall configuration.



  • @aha_1980 I think they checked that already. We will simply switch to a port outside the dynamic range, which seems to fix the issue. We wanted to change the port for a while because it gave us other issues, we just had to deal with some compatibility issues between our client and server for that update.

    Basically, listening on a dynamic port (from 49,152 to 65,535) is a bad idea for at least 2 reasons (now 3, counting this thread):

    • Any program could be using that port at the moment you need it, by having it selected randomly, which will either break the other program, or not let yours use the port at all
    • You can end up with weird self connection issues if the client is idling and searching for a server that is not there.

  • Lifetime Qt Champion

    @samapicoo might be totally unrelated, but Qt 4.7.4 was released before Windows 10, so no one ever tested this configuration.

    Is there any reason you don't upgrade to Qt 5?

    And no, I can't find a good reason the connection would be forbidden, given your investigations are correct.

    Can you show the relevant code?

    Regards



  • A bit more investigation... Switching the port to a different one in the same range gives the same result, but switching the port to 15000 works... I suspect the ephemeral port range is somehow blocked in some cases. Not sure why it would be an intermittent issue, though.

    We are in the process of upgrading to Qt 5... There are just a lot of things to recompile :P

    There is not much code that I can show, other than the pretty straight-forward following:

    if (!TcpServer->listen(QHostAddress::Any, port))
    {
        qWarning() << "Failed to listen on port" << port << "; Error" << TcpServer->serverError() << ": " << TcpServer->errorString();
    

    That code is always run by the same thread that is assigned to the object



  • Looking at the Qt code, I also just realized the error string is independent from the error code... The particular errorString we get with this error is: "The address is protected", which seems to be related to the WSAEACCES error in Windows.


  • Lifetime Qt Champion

    @samapicoo is there any kind of anti virus software running on the machines that fail?



  • @aha_1980 I think they checked that already. We will simply switch to a port outside the dynamic range, which seems to fix the issue. We wanted to change the port for a while because it gave us other issues, we just had to deal with some compatibility issues between our client and server for that update.

    Basically, listening on a dynamic port (from 49,152 to 65,535) is a bad idea for at least 2 reasons (now 3, counting this thread):

    • Any program could be using that port at the moment you need it, by having it selected randomly, which will either break the other program, or not let yours use the port at all
    • You can end up with weird self connection issues if the client is idling and searching for a server that is not there.

Log in to reply