home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / vmsnet / networks / tcpip / ucx / 76 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  2.5 KB

  1. Path: sparky!uunet!stanford.edu!rutgers!ub!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!wmoeng.enet.dec.com!varadaraju
  2. From: varadaraju@wmoeng.enet.dec.com
  3. Newsgroups: vmsnet.networks.tcp-ip.ucx
  4. Subject: Programming a multithreaded server....
  5. Message-ID: <1992Aug20.223257.25714@nntpd.lkg.dec.com>
  6. Date: 20 Aug 92 22:32:57 GMT
  7. Sender: usenet@nntpd.lkg.dec.com (USENET News System)
  8. Reply-To: varadaraju@wmoeng.enet.dec.com ()
  9. Organization: Digital Equipment Corporation
  10. Lines: 88
  11.  
  12.  
  13.     A question regarding TCP sockets and threads:
  14.     
  15.     We have a multithreaded server to which clients
  16.     initially hook up to a well known port - on receiving
  17.     a connection, the server sends back a new port number
  18.     which will be used by the thread spawned for the client.
  19.     
  20.     After sending the port number back, the server spawns
  21.     a thread which binds this new port number to a socket
  22.     and goes on to process the client's requests.
  23.     
  24.     
  25.     The problem we have is that when the client attempts
  26.     to do a connect to the new port, the thread on the server
  27.     side still hasn't done the bind - as a result, we get
  28.     a connection refused error. 
  29.     
  30.     The outline of client and server code is something like this:
  31.     
  32.     
  33.     Client:
  34.     
  35.         x = socket(...);
  36.         
  37.          ... fill sockaddr_in structure...
  38.     
  39.         connect(x, ....);
  40.         recv(x, client_port.....); /* receive the port number on which
  41.                           the server thread will process you */
  42.     
  43.         close(x);
  44.         y = socket(....);
  45.         ... fill sockaddr_in structure with new port...
  46.     
  47.         connect(y, ...); /* this connect fails */
  48.     
  49.         ... talk to the client thread .....
  50.     
  51.     
  52.     
  53.     
  54.     Server:
  55.     
  56.         a = socket(...);
  57.     
  58.         ... fill in sockaddr structure with well known port...
  59.     
  60.         bind(a, sockaddr structure, ....);
  61.     
  62.         listen(a, 5);
  63.     
  64.         b = accept(....);
  65.     
  66.         ... generate a new port number += 1
  67.     
  68.         send(b, new_port_number...);
  69.     
  70.         create thread {
  71.     
  72.             thread:
  73.     
  74.                 c = socket(...);
  75.                 .. fill in sockaddr structure with new port number...
  76.                 bind(c, sockaddr structure....);
  77.                 listen(c, 5);
  78.                 accept(...);  /* This does not happen fast enough
  79.                         */
  80.     
  81.                 ... process client queries....
  82.     
  83.                 }
  84.     
  85.     
  86.     
  87.     The clients run on Ultrix, while the server runs on VMS 5.5 using UCX
  88.     version 1.3. The threads package is CMA Threads.
  89.     
  90.     
  91.     Any info would be appreciated.
  92.     
  93.     
  94.                 -- Kumar Varadaraju
  95.     
  96.     
  97.     
  98.     
  99.     
  100.