sockets and Windows behavior

Dar Scott dsc at
Fri Feb 11 18:13:16 EST 2005

On Feb 11, 2005, at 10:48 AM, John Rule wrote:

>  I noticed that when a socket (regular or datagram) is opened to 
> Windows
> (via my app that is listening on port 1901), an 'alias' port is given
> instead of the 'real' one. For example, if my external device 
> (computer,
> PDA, etc.) connects to socket for communications, 
> the
> actual socket reported is a random number (like 1407), and it changes 
> each
> time the device connects (incrementally..1408, 1409, 1410).

In TCP/IP both TCP and UDP uses the notion of ports.

TCP uses connections and might be easier to explain.  When computer or 
device makes a TCP connection to port 1901 on, 
it needs to assign a port on  In most socket APIs the program 
requesting the connection may specify the port to use on, 
however in most cases it does not and the communications system assigns 
it.  The connection if fully specified by the two address-port pairs.  
Typical socket implementations exploit that and allow multiple 
connections to a passive (listening) end.  Those are all distinct.

So a connection (from the view of is specified by this:

      Remote IP address =
      Remote port       = 1901
      Local IP          =
      Local port        = 1407

Every IP packet has similar information in the header

In Revolution when a connection callback (message) comes in, the IP 
address and the port of the other end are provided.  If the connection 
is broken (or not, actually) and the other end makes another connection 
it is likely to be using another port.  Ports must wait a short time 
before they can be reused, so typically systems just go to the next one 
if a port is not specified.

There are cases in which the process opening the port needs to specify 
the port or at least find out what it is.  Unfortunately there is no 
way to do that in Revolution.  For most protocols this is not needed.  
Since Revolution hides the local port number, if you make multiple 
connections to the same listener, you need to specify an socket id name 
or number in the open.

On the other hand, Revolution accept has no way to specify the IP 
address on a multihomed system.

If you are listening on both TCP and UDP on the same port number, they 
can be confused in Revolution.

UDP is connectionless, but is often handled as though it is a 
connection in sockets implementations and especially the view in 
Revolution.  The same concepts apply roughly.  (UDP is sort of a 
stepchild so folks don't worry about getting it right.  Windows XP 
handles UDP errors poorly.  Most Unix systems don't broadcast in a way 
consistent with the intent of UDP; I argue it is wrong.)

If I missed what you are getting at, I apologize and will try to target 


     DSC (Dar Scott Consulting & Dar's Lab)
     Programming Services and Software

More information about the Use-livecode mailing list