QB64 Phoenix Edition
Connection address weird ports? - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Connection address weird ports? (/showthread.php?tid=3636)



Connection address weird ports? - Parkland - 04-25-2025

Has anyone had issues with _connectionaddress?

I am connecting from one computer to another computer and the computer connecting is using "tcp/ip:50064:radpberrypi"

And the pi accepts the connection but then connectionaddress returns the ip and random port numbers...


RE: Connection address weird ports? - DSMan195276 - 04-25-2025

That's normal, every TCP connection uses two port numbers and they don't usually match - a "source" port and a "destination" port.

The destination port is the number the remote computer is listening on, so 50064 in this case. This number always has to be the same when making a connection so that the remote computer knows a connection is intended for the program listening on 50064.

The source port is a number picked by the machine making the connection, usually randomly from a set range of ports, and it identifies the unique connection being made. A TCP connection is identified by the source and destination port numbers (along with source and destination IPs), so the randomly picked source port allows you to make multiple connections to the same computer on the same destination port - The OS can differentiate which packets belong to which connection by checking the source port.

If the port number had to be the same on both sides of the connection then you wouldn't be able to make multiple TCP connections to the same remote machine on the same destination port - you wouldn't be able to tell the connections apart. This would mean you couldn't do things like request multiple images from a website at the same time, since all the HTTP traffic goes over port 80 or 443. With the randomly-picked source port you can, because while all the image requests share the same destination port they have different source ports.