title: Accept connection on a Listening socket on the Listening socket (and no longer listen)?
body: <p>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.</p>
  
  <p>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.  </p>
  
  <p>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:</p>
  
  <ol>
  <li>Find an available port number, <strong>iPortNumber</strong>.</li>
  <li>Set my socket to listen on <strong>iPortNumber</strong></li>
  <li>Tell Skype to connect CALL ID <strong>iCallID</strong> to PORT number <strong>iPortNumber</strong></li>
  <li>When I get the SessionAvailable event, I know the incoming Skype connection is for CALL ID <strong>iCallID</strong>.</li>
  </ol>
  
  <p>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.</p>
  
  <p>I want to Accept the connection <strong>on</strong> 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?</p>
  
  <p>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.</p>
  
  <p>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.</p>