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

QTcp Server could not be started



  • Hello everyone,

    I'm having a weird error. I'm trying to establish a connection to a server but the Server doesn't seem to start. Here's the Server.cpp:

    Server::Server (QObject *parent) :
    	QTcpServer(parent)
    	{
            }
    void Server::start()
    {
    	QHostAddress pHost;
    	pHost.setAddress("192.168.10.10"); //Setting the Address of the Server to the Address of the target system
    	QString printAddress;
    	printAddress = pHost.toString();
    	printf(QString("starting Host under " + printAddress + " \n").toStdString().c_str()); 
    	if (this->listen(pHost, 8016))
    	{
    		printf(QString("Server started and Listening \n").toStdString().c_str());
    	}
    	else
    	{
    		printf("Server could not be started \n");
    	}
    }
    

    In my main.cpp I instantiate the Server and call the method start.

    Server pServer; 
    pServer.start();
    

    this->listen(pHost, 8016) seems to be returning false because i get "Server could not be started" printed. What am I doing wrong? Why does the Server not start?

    By the Way the Address 192.168.10.10 is the Address of another Computer in the local Network. Maybe that's why I'm getting an Error ?

    I'm trying to establish a connection to that Device. Any Help is highly appreciated !! Thank you !!


  • Qt Champions 2019

    @JohnSRV said in QTcp Server could not be started:

    if (this->listen(pHost, 8016))

    Port numbers bellow 10000 require special rights. Try with a port > 10000.



  • @jsulm thanks for your answer.

    This doesn't seem to be the problem though. I tried various port numbers over 10000 but it didn't work.

    When I use

    if (this->listen(QHostAddress::Any, 2323))
    

    in the constructor, it does work although the port number is under 10000.





  • @JohnSRV said in QTcp Server could not be started:

    By the Way the Address 192.168.10.10 is the Address of another Computer in the local Network. Maybe that's why I'm getting an Error ?

    Could you explain this better?

    You're supposed to start your server listening on an (IP) address that pertain to the computer the server is running from, not the address of another computer in the network...

    Please check documentation for method QTcpServer::listen()


Log in to reply