Q: Accept connection on a Listening socket on the Listening socket (and no longer listen)? I am doing socket programming in Delphi 6 Pro using the ICS (TWSocket) library.  I know my question may seem either convoluted or awkward, but let me explain my application needs so you understand why I want to do something that goes against the usual convention used with a listening socket, that of spinning off an incoming connection to a new socket returned by the Accept method and continue to listen for new connections on the currently set port.
In my application I accept connections from Skype for sending and receiving audio buffers involved with an active Skype call.  The problem is that when Skype connects, there is no handshaking, identification, or authentication that would allow me to know what CALL ID the connection is for.  Since Skype can conference calls together, there can be more than one active call at a time.  However, I need to know which socket connections belong to which CALL ID.  
Since the connection is a "blind" connection as stated above, the only way I can reliably map Skype socket connections to CALL IDs is by controlling carefully the port number I listen on.  Then, when I tell Skype to connect the audio for a given CALL ID to a specific port number, I know that a connection coming in on that socket belongs to that Skype CALL ID.  For example:


*

*Find an available port number, iPortNumber.

*Set my socket to listen on iPortNumber

*Tell Skype to connect CALL ID iCallID to PORT number iPortNumber

*When I get the SessionAvailable event, I know the incoming Skype connection is for CALL ID iCallID.


Rinse and repeat for each CALL ID I need to handle.  I know this means I could end up chewing up a few extra ports but since the number of simultaneous Skype calls is always small I don't see that as a problem.  What I am having difficulty with is the standard convention of having a Listening socket that spins off a new socket using Accept when a new connection comes in.
I want to Accept the connection on the Listening socket (same socket), and then specifically stop listening without having to close the connection since I don't want to accept any new connections on that port number anymore.  Is there a way to do this?
An alternative avenue would be to use the newly created socket returned by Accept and then close the Listening socket, but then I have to come up with a more complicated method to track port numbers to Skype CALL IDs because, if I am correct in my knowledge, the newly created socket returned by Accept is connected on a different port number than the Listening socket so the Listening socket can keep listening on the existing port number.  I'd like to avoid that extra complexity and hassle if I could.
If anyone has a better overall idea/paradigm on how to map my blind Skype connections to the Skype CALL IDs that are tied to them, please let me know.  Also, I don't think it's possible, but if there's a clever way to get the process ID behind an incoming Socket connection from a process connecting on the same system as my app, I'd like to know.

A: One-time listening sockets are not that unusual.  The FTP protocol uses them, for instance.  Simply create a new listening socket on the desired port (or let the socket decide its own port that you can then retrieve), set its backlog to 1, then call accept() on it just once and close it.  If accept() accepts a client connection, it returns a new socket handle that you use to communicate with that client.  You don't need to keep the listening socket alive during that time.
I don't know what the ICS equivilent of that operation would be, but in Indy there is a TIdSimpleServer component for exactly this purpose (incidentally, Skype on Windows uses Indy).
