net-listen and sockets
Posted: Mon Sep 01, 2008 8:00 am
I needed to do some research on TCP and UDP connections. I was going through the relevant functions in newLISP and found (net-listen) with this description
There seems to be a small but significant conflict here. "... net-listen returns immediately with a socket number" versus "As soon as a connection is accepted [by net-accept], net-accept returns a socket number...")
On the face of it, this description has (net-listen) first returning a socket number when it begins listening, and then (net-accept) returning a socket number when a connection is established. How can both functions return a socket number? And if both do, why does (net-listen) return one at all?
I did a little testing in termianl mode and found that indeed (net-listen 2000) returned immediatley with the integer 112. But in my literature research I found that if a diagnostics tool is run to check for the IP address and port of the server or remote client, then *until* a connection is established, the most common result is to display IP 0.0.0.0 and port 0. So I ran (net-local 112) and it retuned ("0.0.0.0" 2000).
And further, I found that *until* a connection is established, the socket number does not exist, because the socket number is the mapping to the connection details of the server and client. So, if no connection, nothing to map, so no socket number is generated. So (net-accept) is where the real socket number should be created.
If this is correct, then the first part of the quotation above, "... net-listen returns immediately with a socket number", cannot be correct. At best , it would return with a *potential* socket number, or an intermediate pseudo-socket number, or whatever. So what in reality is it that (net-listen) is returning?
I also then ran (net-peer 112), expecting to see ("0.0.0.0" 0) returned. But instead, it returned ("" 0).
A call to net-listen returns immediately with a socket number, which is then used by the blocking net-accept function to wait for a connection. As soon as a connection is accepted, net-accept returns a socket number that can be used to communicate with the connecting client.
There seems to be a small but significant conflict here. "... net-listen returns immediately with a socket number" versus "As soon as a connection is accepted [by net-accept], net-accept returns a socket number...")
On the face of it, this description has (net-listen) first returning a socket number when it begins listening, and then (net-accept) returning a socket number when a connection is established. How can both functions return a socket number? And if both do, why does (net-listen) return one at all?
I did a little testing in termianl mode and found that indeed (net-listen 2000) returned immediatley with the integer 112. But in my literature research I found that if a diagnostics tool is run to check for the IP address and port of the server or remote client, then *until* a connection is established, the most common result is to display IP 0.0.0.0 and port 0. So I ran (net-local 112) and it retuned ("0.0.0.0" 2000).
And further, I found that *until* a connection is established, the socket number does not exist, because the socket number is the mapping to the connection details of the server and client. So, if no connection, nothing to map, so no socket number is generated. So (net-accept) is where the real socket number should be created.
If this is correct, then the first part of the quotation above, "... net-listen returns immediately with a socket number", cannot be correct. At best , it would return with a *potential* socket number, or an intermediate pseudo-socket number, or whatever. So what in reality is it that (net-listen) is returning?
I also then ran (net-peer 112), expecting to see ("0.0.0.0" 0) returned. But instead, it returned ("" 0).