Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Sockets Programming Question
Alegen last edited by
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
tbscope last edited by
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).
goetz last edited by
[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.