sockets and Windows behavior

Dar Scott dsc at swcp.com
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 192.168.77.10:1901 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 10.0.0.1 makes a TCP connection to port 1901 on 192.168.77.10, 
it needs to assign a port on 10.0.0.1.  In most socket APIs the program 
requesting the connection may specify the port to use on 10.0.0.1, 
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 10.0.0.1) is specified by this:

      Remote IP address = 192.168.77.10
      Remote port       = 1901
      Local IP          = 10.0.0.1
      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 
that.

Dar

-- 
**********************************************
     DSC (Dar Scott Consulting & Dar's Lab)
     http://www.swcp.com/dsc/
     Programming Services and Software
**********************************************



More information about the use-livecode mailing list