home *** CD-ROM | disk | FTP | other *** search
- 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
- From: varadaraju@wmoeng.enet.dec.com
- Newsgroups: vmsnet.networks.tcp-ip.ucx
- Subject: Programming a multithreaded server....
- Message-ID: <1992Aug20.223257.25714@nntpd.lkg.dec.com>
- Date: 20 Aug 92 22:32:57 GMT
- Sender: usenet@nntpd.lkg.dec.com (USENET News System)
- Reply-To: varadaraju@wmoeng.enet.dec.com ()
- Organization: Digital Equipment Corporation
- Lines: 88
-
-
- A question regarding TCP sockets and threads:
-
- We have a multithreaded server to which clients
- initially hook up to a well known port - on receiving
- a connection, the server sends back a new port number
- which will be used by the thread spawned for the client.
-
- After sending the port number back, the server spawns
- a thread which binds this new port number to a socket
- and goes on to process the client's requests.
-
-
- The problem we have is that when the client attempts
- to do a connect to the new port, the thread on the server
- side still hasn't done the bind - as a result, we get
- a connection refused error.
-
- The outline of client and server code is something like this:
-
-
- Client:
-
- x = socket(...);
-
- ... fill sockaddr_in structure...
-
- connect(x, ....);
- recv(x, client_port.....); /* receive the port number on which
- the server thread will process you */
-
- close(x);
- y = socket(....);
- ... fill sockaddr_in structure with new port...
-
- connect(y, ...); /* this connect fails */
-
- ... talk to the client thread .....
-
-
-
-
- Server:
-
- a = socket(...);
-
- ... fill in sockaddr structure with well known port...
-
- bind(a, sockaddr structure, ....);
-
- listen(a, 5);
-
- b = accept(....);
-
- ... generate a new port number += 1
-
- send(b, new_port_number...);
-
- create thread {
-
- thread:
-
- c = socket(...);
- .. fill in sockaddr structure with new port number...
- bind(c, sockaddr structure....);
- listen(c, 5);
- accept(...); /* This does not happen fast enough
- */
-
- ... process client queries....
-
- }
-
-
-
- The clients run on Ultrix, while the server runs on VMS 5.5 using UCX
- version 1.3. The threads package is CMA Threads.
-
-
- Any info would be appreciated.
-
-
- -- Kumar Varadaraju
-
-
-
-
-
-