@Andy B No doubt.
However, I'm not sure how that would lead to an understanding of the Xojo syntax and functionality, especially since the VB.NET version returns the random port. My real problem I think is my inexperience with Xojo.
Sorry but I am with Maurizio on this. The real problem is not Xojo or vb .net but rather (being cynical) the propensity of software developers to skip the TCP primer and wade into network applications. There are many issues with Xojo's network classes but this is not one of them.
The Xojo TCP socket class is essentially a wrapper around the Berkeley Sockets API used to build the underlying OS and the functionality is similar. The VB .NET implementation appears to be abstracted a little further (for better or worse) but depends on the very same underlying API.
What you are calling a 'random port' is not random at all. Within the UDP and TCP protocols a port address may be 'reserved,' it may be 'well known,' it may be 'ephemeral,' but it must never be 'random.'
To answer your question, consider the empirical assertion.
All TCP packets destined for a web server application must have 80 in the destination port field, regardless of the originating web browser. All packets sent from a web server must therefore have 80 in the source port field, regardless of the port in the destination field.
From the assertion we may infer. i) There are two sockets involved in a TCP conversation. ii) One socket is bound to your application (local). iii) The other socket is bound to a different application that may be on a different device (remote). iv) One socket's port address is and must be known before a connection can be established. v) The other socket's port address may not be known before a connection is established.
When you are looking at a web server process, and see a port address that is a large number, you may deduce that the port address you are looking at is not the local port address, within the 'well known' ports range. The large number is probably within the 'ephemeral' range and is probably the remote port address of a connected web browser.
Sure enough, when I take a look at your vb .net code, at line #13 I find the local port address is 50000. On line #28 I find the code refers to LANClient.Client.RemoteEndPoint, the remote port address.
The vb .net and Xojo socket interfaces are behaving the same way (because they have to) but you have incorrectly assumed you are looking at the same socket property, which you are not. Xojo's TCPSocket.Port refers to the local port address; embedded in the source port field of the TCP packet headers your application writes to the wire. The vb .net Client.RemoteEndPoint refers to the remote port address; embedded in the source port field of the TCP packet headers your application reads from the wire.