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. TCP Client static port

TCP Client static port

Scheduled Pinned Locked Moved Solved General and Desktop
tcptcpsocketportsocketsockets
5 Posts 2 Posters 461 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.
  • J Offline
    J Offline
    Joe von Habsburg
    wrote on 16 Apr 2024, 11:30 last edited by
    #1

    Hi, I can connect to TCP server but I want to give spesific port number to client.

    REMOTE_PORT = 5001;
    _client->connectToHost(REMOTE_ADDRESS, REMOTE_PORT);
    

    remote port number is 5001 and I can connect it. But every time my port number is change.
    How can I set spesefic port number to my client ?

    J 1 Reply Last reply 16 Apr 2024, 11:35
    0
    • J Joe von Habsburg
      16 Apr 2024, 11:30

      Hi, I can connect to TCP server but I want to give spesific port number to client.

      REMOTE_PORT = 5001;
      _client->connectToHost(REMOTE_ADDRESS, REMOTE_PORT);
      

      remote port number is 5001 and I can connect it. But every time my port number is change.
      How can I set spesefic port number to my client ?

      J Offline
      J Offline
      JonB
      wrote on 16 Apr 2024, 11:35 last edited by JonB
      #2

      @Joe-von-Habsburg
      Before answering this, why do you want to pick a specific port number at client side or care about what "random" port number TCP will pick for it without you doing so? Usually one does not, server specifies a port, clients connect using some local free port and that's all good. Yes, the client side port number will likely change each time, again that's fine.

      J 1 Reply Last reply 16 Apr 2024, 11:43
      1
      • J JonB
        16 Apr 2024, 11:35

        @Joe-von-Habsburg
        Before answering this, why do you want to pick a specific port number at client side or care about what "random" port number TCP will pick for it without you doing so? Usually one does not, server specifies a port, clients connect using some local free port and that's all good. Yes, the client side port number will likely change each time, again that's fine.

        J Offline
        J Offline
        Joe von Habsburg
        wrote on 16 Apr 2024, 11:43 last edited by
        #3

        @JonB because I want to watch message communication on my port

        I create client like that. And I connect to server.

        _client = new QTcpSocket(this);
        _client->connectToHost(REMOTE_ADDRESS, REMOTE_PORT);
        
        J 1 Reply Last reply 16 Apr 2024, 11:49
        0
        • J Joe von Habsburg
          16 Apr 2024, 11:43

          @JonB because I want to watch message communication on my port

          I create client like that. And I connect to server.

          _client = new QTcpSocket(this);
          _client->connectToHost(REMOTE_ADDRESS, REMOTE_PORT);
          
          J Offline
          J Offline
          JonB
          wrote on 16 Apr 2024, 11:49 last edited by JonB
          #4

          @Joe-von-Habsburg
          You may be out luck, at least easily! Looks like I answered this in https://forum.qt.io/topic/100018/qtcpsocket-how-to-set-local-port in 2019!

          If it looks like further support was never added, I am suggesting those links are still valid and show you how you may achieve it from Qt.

          There I suggested how it might be achieved with low-level calls, you could try.

          Also perhaps https://gist.github.com/atomass/fadbc33039aa22991cfef1ea65ae9334

          Most people who want to see traffic still manage without knowing client side port number, diagnostics show which server port it is connected to and you just work with that.

          J 1 Reply Last reply 16 Apr 2024, 14:35
          1
          • J JonB
            16 Apr 2024, 11:49

            @Joe-von-Habsburg
            You may be out luck, at least easily! Looks like I answered this in https://forum.qt.io/topic/100018/qtcpsocket-how-to-set-local-port in 2019!

            If it looks like further support was never added, I am suggesting those links are still valid and show you how you may achieve it from Qt.

            There I suggested how it might be achieved with low-level calls, you could try.

            Also perhaps https://gist.github.com/atomass/fadbc33039aa22991cfef1ea65ae9334

            Most people who want to see traffic still manage without knowing client side port number, diagnostics show which server port it is connected to and you just work with that.

            J Offline
            J Offline
            Joe von Habsburg
            wrote on 16 Apr 2024, 14:35 last edited by
            #5

            @JonB thank you so much

            1 Reply Last reply
            0
            • J Joe von Habsburg has marked this topic as solved on 16 Apr 2024, 14:35

            1/5

            16 Apr 2024, 11:30

            • Login

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