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

  1. Newsgroups: comp.unix.wizards
  2. Path: sparky!uunet!digex.com!intercon!udel!gatech!hubcap!ncrcae!grok101.ColumbiaSC.NCR.COM!raj
  3. From: raj@grok101.ColumbiaSC.NCR.COM (0000-Admin(0000))
  4. Subject: Re: client/server question...........
  5. Message-ID: <1993Jan27.112155.21987@ncrcae.ColumbiaSC.NCR.COM>
  6. Sender: root@grok101.ColumbiaSC.NCR.COM (0000-Admin(0000))
  7. Nntp-Posting-Host: grok101.columbiasc.ncr.com
  8. Organization: Your Organization Here
  9. References: <1993Jan26.222115.28187@slate.mines.colorado.edu>
  10. Date: Wed, 27 Jan 93 16:21:54 GMT
  11. Lines: 57
  12.  
  13. In article <1993Jan26.222115.28187@slate.mines.colorado.edu>, iarit@slate.mines.colorado.edu (ARIT ISMAIL) writes:
  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. |> Here is what I am trying to do;
  20. |> 
  21. |> I want to write a program that will accept connections from
  22. |> other programs and will communicate with them without forking.
  23. |> I don't want to fork because the info should be generated on one
  24. |> program, send to server and the server has to respond to every
  25. |> program connected with the same info( if I fork, how  can I transfer
  26. |> that info to child?).
  27. |> 
  28. |>   main                     main
  29. |>   client <--> server <--> client
  30. |>                 |
  31. |>                 |
  32. |>          _______________________________
  33. |>          |         |        |        |
  34. |>          v         v        v        v
  35. |>        client1  client2  client3     ......
  36. |> 
  37. |> (main clients generate the info)
  38. |> I know this is not an easy thing to do, but actually, I am having
  39. |> problems with accept(..);
  40. |> can I do something like this;
  41. |> 
  42. |> while(1)
  43. |> {
  44. |>  check_new_connection(); /* how can I check if there is any new
  45. |> connection
  46. |>                            without waiting, as far as I know accept(..)
  47. |>                            blocks you 'till you get some connection*/
  48. |>  check_clients();       /* I can do these, no problem. read if there is
  49. |>                            any new info */
  50. |>  if(thereIsNewInfo)
  51. |>    inform_clients();     /* if I can create a list of handles for clients
  52. |>                            this is no big deal */
  53. |> 
  54. |> }
  55. |> My problem is getting new connections without waiting.
  56.     If your problem is only about having a non-blocking "accept()", then
  57. you mark the socket as non-blocking. If you then try accept() , you will see
  58. that accept will accept the connection, if there is a pending connection request.
  59. On the other hand if no pending connections are there, then accept 
  60. will return immediately with an error (I think EWOULDBLOCK).
  61. You can use fcntl (O_NDELAY or O_NONBLOCK) for the server socket to get this
  62. feature.
  63.  
  64. |> 
  65. |> I appreciate any help.
  66. |> 
  67. |> iarit@slate.mines.colorado.edu
  68. -raj
  69. 1/27/93
  70.