Article View: comp.unix.wizards
Article #6950Re: client/server question...........
From: 0000-Admin(0000)
Date: Wed, 27 Jan 1993 16:21
Date: Wed, 27 Jan 1993 16:21
57 lines
2845 bytes
2845 bytes
In article <1993Jan26.222115.28187@slate.mines.colorado.edu>, iarit@slate.mines.colorado.edu (ARIT ISMAIL) writes:
|> Hi,
|>
|> I don't know if this is the right place to post this, but
|> I need some help about writing a simple client/server program.
|>
|> Here is what I am trying to do;
|>
|> I want to write a program that will accept connections from
|> other programs and will communicate with them without forking.
|> I don't want to fork because the info should be generated on one
|> program, send to server and the server has to respond to every
|> program connected with the same info( if I fork, how can I transfer
|> that info to child?).
|>
|> main main
|> client <--> server <--> client
|> |
|> |
|> _______________________________
|> | | | |
|> v v v v
|> client1 client2 client3 ......
|>
|> (main clients generate the info)
|> I know this is not an easy thing to do, but actually, I am having
|> problems with accept(..);
|> can I do something like this;
|>
|> while(1)
|> {
|> check_new_connection(); /* how can I check if there is any new
|> connection
|> without waiting, as far as I know accept(..)
|> blocks you 'till you get some connection*/
|> check_clients(); /* I can do these, no problem. read if there is
|> any new info */
|> if(thereIsNewInfo)
|> inform_clients(); /* if I can create a list of handles for clients
|> this is no big deal */
|>
|> }
|> My problem is getting new connections without waiting.
If your problem is only about having a non-blocking "accept()", then
you mark the socket as non-blocking. If you then try accept() , you will see
that accept will accept the connection, if there is a pending connection request.
On the other hand if no pending connections are there, then accept
will return immediately with an error (I think EWOULDBLOCK).
You can use fcntl (O_NDELAY or O_NONBLOCK) for the server socket to get this
feature.
|>
|> I appreciate any help.
|>
|> iarit@slate.mines.colorado.edu
-raj
1/27/93
Technical Details
Message-ID:
<1993Jan27.112155.21987@ncrcae.ColumbiaSC.NCR.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!digex.com!intercon!udel!gatech!hubcap!ncrcae!grok101.ColumbiaSC.NCR.COM!rajReferences:
<1993Jan26.222115.28187@slate.mines.colorado.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.unix.wizards Path: arc1-ca.pugleaf.net!sparky!uunet!digex.com!intercon!udel!gatech!hubcap!ncrcae!grok101.ColumbiaSC.NCR.COM!raj From: raj@grok101.ColumbiaSC.NCR.COM (0000-Admin(0000)) Subject: Re: client/server question........... Message-ID: <1993Jan27.112155.21987@ncrcae.ColumbiaSC.NCR.COM> Sender: root@grok101.ColumbiaSC.NCR.COM (0000-Admin(0000)) Nntp-Posting-Host: grok101.columbiasc.ncr.com Organization: Your Organization Here References: <1993Jan26.222115.28187@slate.mines.colorado.edu> Date: Wed, 27 Jan 93 16:21:54 GMT Lines: 57