home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / wizards / 5678 < prev    next >
Encoding:
Text File  |  1993-01-28  |  3.0 KB  |  91 lines

  1. Newsgroups: comp.unix.wizards
  2. Path: sparky!uunet!brunix!cs.brown.edu!jg
  3. From: jg@cs.brown.edu (Jeremy Gaffney)
  4. Subject: Re: client/server question...........
  5. Message-ID: <1993Jan28.230852.9470@cs.brown.edu>
  6. Sender: news@cs.brown.edu
  7. Organization: Brown Computer Science Dept.
  8. References:  <1993Jan26.222115.28187@slate.mines.colorado.edu>
  9. Date: Thu, 28 Jan 1993 23:08:52 GMT
  10. Lines: 79
  11.  
  12. In article <1993Jan26.222115.28187@slate.mines.colorado.edu>, iarit@slate.mines.colorado.edu (ARIT ISMAIL) writes:
  13. |> Hi,
  14. Hi.
  15. |> 
  16. |> I don't know if this is the right place to post this, but
  17. |> I need some help about writing a simple client/server program.
  18.  
  19. Comp.unix.questions is usually a better forum for 
  20. questions of this level.  I also highly recommend 
  21. getting W. Richard Stevens' Unix_Network_Programming, 
  22. which is an excellent reference with a large amount of
  23. robust source code included.  The book is the best networking
  24. reference I have seen.  It will be a well-spent $50.
  25.  
  26. |> 
  27. |> Here is what I am trying to do;
  28. |> 
  29. |> I want to write a program that will accept connections from
  30. |> other programs and will communicate with them without forking.
  31. |> I don't want to fork because the info should be generated on one
  32. |> program, send to server and the server has to respond to every
  33. |> program connected with the same info( if I fork, how  can I transfer
  34. |> that info to child?).
  35.  
  36. Shared memory. Sockets. Pipes.  Man pages are:
  37.  
  38. shmctl (2)              - shared memory control operations
  39. shmget (2)              - get shared memory segment identifier
  40. shmop, shmat, shmdt (2) - shared memory operations
  41.  
  42. for shared memory,
  43.  
  44. socket(2), connect(2), et al. for sockets, and 
  45.  
  46. pipe (2V)               - create an interprocess communication channel
  47. popen, pclose (3S)      - open or close a pipe (for I/O) from or to a process
  48.  
  49. for pipes.  These three are common and reasonably portable. 
  50.  
  51. |> 
  52. |> while(1)
  53. |> {
  54. |>  check_new_connection(); /* how can I check if there is any new
  55. |> connection
  56. |>                            without waiting, as far as I know accept(..)
  57. |>                            blocks you 'till you get some connection*/
  58. |>  check_clients();       /* I can do these, no problem. read if there is
  59. |>                            any new info */
  60. |>  if(thereIsNewInfo)
  61. |>    inform_clients();     /* if I can create a list of handles for clients
  62. |>                            this is no big deal */
  63. |> 
  64. |> }
  65. |> My problem is getting new connections without waiting.
  66.  
  67. To get new connections without waiting, you can set the socket to
  68. be non-blocking using the ioctl or fnctl calls, like so:
  69.  
  70. #include <sys/ioctl.h>
  71. #include <errno.h>
  72.  
  73. char foo=(char) 1;
  74.  
  75. if (ioctl(sockfd, FIONBIO, &foo  ) < 0)
  76.     printf("Error setting socket %d with code: %d", sockfd, errno);
  77.  
  78. The third argument is a char * which is expected to point
  79. to the argument to ioctl; arg needs merely to be non-zero in
  80. this case to set nonblocking IO for sockfd.
  81.  
  82. |> 
  83. |> I appreciate any help.
  84. |> 
  85. |> iarit@slate.mines.colorado.edu
  86.  
  87. Anytime.
  88. -jg
  89. -- 
  90. /*  Jeremy Gaffney [jg@cs.brown.edu gaffer@brownvm.brown.edu] */
  91.