Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTcp Server could not be started
Qt 6.11 is out! See what's new in the release blog

QTcp Server could not be started

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 627 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JohnSRV
    wrote on last edited by
    #1

    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 !!

    jsulmJ JonBJ Pablo J. RoginaP 3 Replies Last reply
    0
    • J JohnSRV

      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 !!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply
      0
      • jsulmJ jsulm

        @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.

        J Offline
        J Offline
        JohnSRV
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • J JohnSRV

          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 !!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @JohnSRV said in QTcp Server could not be started:

          i get "Server could not be started" printed.

          https://doc.qt.io/qt-5/qtcpserver.html#errorString

          1 Reply Last reply
          2
          • J JohnSRV

            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 !!

            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #5

            @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()

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            3

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved