2ee54f55   
   From: barmar@alum.mit.edu   
      
   In article   
   ,   
    "lovecreatesbeauty@gmail.c0m" wrote:   
      
   > On Apr 7, 6:09 pm, David Schwartz wrote:   
   > > On Apr 6, 11:46 pm, "lovecreatesbea...@gmail.c0m"   
   > >   
   > > > 3. If a client program doesn't know the server program name(eg.   
   > > > `svr_abc', `a.out') and the port number the server is listening on,   
   > > > can the client still detect and connect to the server program?   
   > >   
   > > Sure, by any mechanism you choose to code.   
   > >   
   >   
   > Thank you.   
   >   
   > Can I do this sort of things?   
   >   
   > A socket server side program's bind(2) to port number `PORT_ABC'.   
   > Suppose a socket client side program doesn't know the value of that   
   > PORT_ABC. It tries all ports range from 0 (or 1024) to USHRT_MAX (max.   
   > of type of sin_port) until `no' ECONNREFUSED thrown on connect(2).   
   >   
   > (If there's only one socket server program bound and listening to only   
   > one port `PORT_ABC' on a host machine, can a client do above things?)   
      
   That's a really big assumption. Most computers tend to have multiple   
   servers running, so you'll probably run into something else before you   
   hit the port being used by this application.   
      
   There are two ways that this is typically done:   
      
   1. A portmapper. This listens on a well-known port and runs a directory   
   service that tells the ports being used by other applications. When a   
   server starts up, it binds to an ephemeral port and registers it with   
   the portmapper. Clients ask the portmapper for this port. This   
   basically just adds a level of indirection -- instead of a well-known   
   port for each service, you need a well-known service identifier of some   
   kind. But this can make things easier, since service identifiers can   
   allow a wider range (port numbers are only 16 bits), perhaps even   
   strings instead of numbers.   
      
   2. Primary vs. auxiliary connection. The initial connection to the   
   server uses a well-known port. Additional connections use ephemeral   
   ports, and the port number is communicated on the primary connection.   
   An example of this is FTP: the control connection uses port 21, data   
   connections use ephemeral ports.   
      
   --   
   Barry Margolin, barmar@alum.mit.edu   
   Arlington, MA   
   *** PLEASE don't copy me on replies, I'll read them in the group ***   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|