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. Simple Qt server and open ports.
QtWS25 Last Chance

Simple Qt server and open ports.

Scheduled Pinned Locked Moved General and Desktop
httpserverports
5 Posts 2 Posters 2.0k Views
  • 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.
  • ealioneE Offline
    ealioneE Offline
    ealione
    wrote on last edited by
    #1

    I have created a very basic server that all it does is echo all the messages it receives.

    I originally chose a port for the server and everything seemed fine. Upon running it again though it said that it cannot use that port since it is in use. So I had to change the port my server was to listen to.

    I have to do this every time I re-run my server. Is there any way upon closing my server to also free the port so it can be used again?

    M 1 Reply Last reply
    0
    • ealioneE ealione

      I have created a very basic server that all it does is echo all the messages it receives.

      I originally chose a port for the server and everything seemed fine. Upon running it again though it said that it cannot use that port since it is in use. So I had to change the port my server was to listen to.

      I have to do this every time I re-run my server. Is there any way upon closing my server to also free the port so it can be used again?

      M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      @ealione said:

      Upon running it again though it said that it cannot use that port since it is in use.

      This means that the listening socket is not closed properly when the application exit.

      I also suggest to use QAbstractSocket::ReuseAddressHint to allow to reuse the port; this is very useful when your server crashes

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • ealioneE Offline
        ealioneE Offline
        ealione
        wrote on last edited by
        #3

        Hi mcosta,
        How is one expected to properly close the socket?
        My server was based on a tutorial by voidRealms on youtube and it was for an earlier version of Qt, so it is possible that things have changed.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Hi, can you post the code that manages the socket?

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • ealioneE Offline
            ealioneE Offline
            ealione
            wrote on last edited by
            #5

            This must be the part that you want

            void MyServer::StartServer()
            {
            thisIp = 2346;

            if(!this->listen(QHostAddress::Any, thisIp))
            {
                qDebug() << "Could not start server.";
                qDebug() << errorString();
            }
            else
            {
                qDebug() << "Listening at" << thisIp;
            }
            

            }

            and here is the original. tutorial.

            1 Reply Last reply
            0

            • Login

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