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. Several TCP servers listening on the same port

Several TCP servers listening on the same port

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 3.4k 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.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #1

    Does anybody know if it is allowed for more than one TCP server to listen at a specific port for in-coming connections?

    I am using QTcpServer to listen on the same port for in-coming connections, but obviously only one of the servers is receiving the in-coming connection.

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • O Offline
      O Offline
      Overflowz
      wrote on last edited by
      #2

      Have you tried using threads?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luca
        wrote on last edited by
        #3

        It's not possible.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          [quote author="Overflowz" date="1353673408"]Have you tried using threads?[/quote]
          No. Basically different instances of the same application started. I came across the issue when using a server port to shut down gracefully.
          If I remember correctly, I could shut down the first instance. However, even so, the port wasn't occupied anymore, the second instance did not receive later connects.

          [quote author="Luca" date="1353674676"]It's not possible.[/quote]
          It is possible to close the server listening on a specific port, but leave the application running. Can the other application listen to port now? Any experience already?

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alexisdm
            wrote on last edited by
            #5

            [quote author="koahnig" date="1353683205"]It is possible to close the server listening on a specific port, but leave the application running. Can the other application listen to port now? Any experience already?[/quote]
            The other application needs to reopen the port explicitly after the port is freed. You can't listen to a port that is already open by another application, you'll receive an error if you try (QTcpServer::listen would returns false, and QTcpServer::errorString would say why it returned false).

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              You can technically re-open a port that is already opened (using the SO_REUSEADDR socket option), but it may lead to undefined behaviour if both applications use the socket simultaneously.

              It is amongst others used to "pick up" the port if the application has died and the port hasn't been released yet by the system, and the other one should step in - which might be the source of error in your case.

              UDP multicast sockets allow for multiple applications subscribing to the same port simultaneously if this is an option for you.

              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