Professional Web Applications Themes

connect() ing from within server - UNIX Programming

Hi, I want to develop a socket program where the server program binds and accepts on a TCP socket. After that the same server program forks() 10 children processes which in turn connect to the parent (server here) on the TCP connection. Now my problem is if I use accept(), the program won't go ahead and hence wont generate child processes, until the accept() call returns. and unless the child processes are generated, there is nobody to connect() to the server. I am planning to use non-blocking system calls like poll() and select(), but I am not sure whether it ...

  1. #1

    Default connect() ing from within server

    Hi,

    I want to develop a socket program where the server program binds and
    accepts on a TCP socket. After that the same server program forks() 10
    children processes which in turn connect to the parent (server here)
    on the TCP connection.

    Now my problem is if I use accept(), the program won't go ahead and
    hence wont generate child processes, until the accept() call returns.
    and unless the child processes are generated, there is nobody to
    connect() to the server.

    I am planning to use non-blocking system calls like poll() and
    select(), but I am not sure whether it will solve my problem.

    It would be gr8 if somebody could guide me to its solution.

    Regards,
    Tejas Kokje
    Tejas Guest

  2. #2

    Default Re: connect() ing from within server


    "Tejas Kokje" <edu> wrote in message
    news:google.com...

     


    Do you really mean *after* it accepts a connection? Why not fork off the
    child processes before you call 'accept'. Just don't forget that the
    children will have to wait until the parent is ready.

    Otherwise, you can create a miniature scheduler. Before you call
    'accept', set an 'alarm' to interrupt the 'accept' when it's time to do
    something else. Don't forget to disarm the alarm when 'accept' returns.

     


    Right, so you either need to create the children first or not use a
    blocking 'accept' (at least, not indefinitely blocking).

     


    That's one way to do it, just make sure to make the sockets non-blocking
    or you'll have race conditions.

    DS




    David Guest

  3. #3

    Default Re: connect() ing from within server

    Hi

    How to make child process wait for parent to get ready ?

    Regards,
    Tejas





    Tejas Guest

  4. #4

    Default Re: connect() ing from within server

    In article <c208h4$iqs$usc.edu>, Tejas Kokje <edu>
    wrote:
     

    The parent should get ready *before* forking the children, to avoid the
    problem.

    --
    Barry Margolin, mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Guest

  5. #5

    Default Re: connect() ing from within server

    Tejas Kokje wrote: 

    Keep retrying the connection until it succeeds?

    --
    Pull out a splinter to reply.
    Peter Guest

Similar Threads

  1. Can't connect to Apache Server (jrun server not found)
    By TwistedMind1979 in forum Coldfusion - Getting Started
    Replies: 3
    Last Post: June 16th, 08:58 PM
  2. Replies: 2
    Last Post: September 12th, 10:44 PM
  3. Replies: 0
    Last Post: August 23rd, 05:27 PM
  4. Replies: 1
    Last Post: September 27th, 09:18 PM
  5. Replies: 0
    Last Post: July 1st, 02:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139