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. Sockets Programming Question
Forum Updated to NodeBB v4.3 + New Features

Sockets Programming Question

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.7k 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.
  • A Offline
    A Offline
    Alegen
    wrote on 11 Feb 2011, 11:11 last edited by
    #1

    Hello all!

    I have a sockets programming question. I have a QTcpServer listening to a port, when new connections are available, they are returned by nextPendingConnection as a QTcpSocket which uses the same port as QTcpServer. Now let's say that I have two different QTcpSockets using the same port, plus the QTcpServer which is also listening to it. This means 3 objects using the same port to communicate.

    Now my question is, if new data arrives and it is meant for QTcpSocket 1, what happens to QTcpSocket 2 and the QTcpServer? Can they see this new data? Can they 'steal' it from QTcpSocket 1?

    Thanks in advance

    << something smart >>
    (signatures always contain something like that)

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tbscope
      wrote on 11 Feb 2011, 11:16 last edited by
      #2

      You also have an ip address of course.
      TCP works via handshakes.

      But, even then, yes, you need to make sure you implement safety (for all sorts of problems).

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on 11 Feb 2011, 11:53 last edited by
        #3

        [quote author="Alegen" date="1297422715"]Now my question is, if new data arrives and it is meant for QTcpSocket 1, what happens to QTcpSocket 2 and the QTcpServer? Can they see this new data? Can they 'steal' it from QTcpSocket 1?
        Thanks in advance[/quote]

        This is handled by the OS/Qt:

        bq. Wikipedia on "Berkeley Sockets":http://en.wikipedia.org/wiki/Berkeley_sockets
        accept() is used on the server side. It accepts a received incoming attempt to create a new TCP connection from the remote client, and creates a new socket associated with the socket address pair of this connection.

        In fact the connection is determined by

        • listening socket IP address
        • listening socket port number
        • connecting socket IP address
        • connecting socket port number

        This quadruple unambiguously identifies the connection. In case of NAT coming into the game or some application is connecting in parallel, the connecting IP address is the same, but the ports do differ.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0

        1/3

        11 Feb 2011, 11:11

        • Login

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