home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.wizards
- Path: sparky!uunet!brunix!cs.brown.edu!jg
- From: jg@cs.brown.edu (Jeremy Gaffney)
- Subject: Re: client/server question...........
- Message-ID: <1993Jan28.230852.9470@cs.brown.edu>
- Sender: news@cs.brown.edu
- Organization: Brown Computer Science Dept.
- References: <1993Jan26.222115.28187@slate.mines.colorado.edu>
- Date: Thu, 28 Jan 1993 23:08:52 GMT
- Lines: 79
-
- In article <1993Jan26.222115.28187@slate.mines.colorado.edu>, iarit@slate.mines.colorado.edu (ARIT ISMAIL) writes:
- |> Hi,
- 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.
-
- Comp.unix.questions is usually a better forum for
- questions of this level. I also highly recommend
- getting W. Richard Stevens' Unix_Network_Programming,
- which is an excellent reference with a large amount of
- robust source code included. The book is the best networking
- reference I have seen. It will be a well-spent $50.
-
- |>
- |> 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?).
-
- Shared memory. Sockets. Pipes. Man pages are:
-
- shmctl (2) - shared memory control operations
- shmget (2) - get shared memory segment identifier
- shmop, shmat, shmdt (2) - shared memory operations
-
- for shared memory,
-
- socket(2), connect(2), et al. for sockets, and
-
- pipe (2V) - create an interprocess communication channel
- popen, pclose (3S) - open or close a pipe (for I/O) from or to a process
-
- for pipes. These three are common and reasonably portable.
-
- |>
- |> 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.
-
- To get new connections without waiting, you can set the socket to
- be non-blocking using the ioctl or fnctl calls, like so:
-
- #include <sys/ioctl.h>
- #include <errno.h>
-
- char foo=(char) 1;
-
- if (ioctl(sockfd, FIONBIO, &foo ) < 0)
- printf("Error setting socket %d with code: %d", sockfd, errno);
-
- The third argument is a char * which is expected to point
- to the argument to ioctl; arg needs merely to be non-zero in
- this case to set nonblocking IO for sockfd.
-
- |>
- |> I appreciate any help.
- |>
- |> iarit@slate.mines.colorado.edu
-
- Anytime.
- -jg
- --
- /* Jeremy Gaffney [jg@cs.brown.edu gaffer@brownvm.brown.edu] */
-