in reply to Socket programming & CGI hell

Because your CGI program is basically an "execute once" type program, your server needs to behave apropriately. There is no point in your server keeping the connection open because once the client (.cgi program) has completed it will close the socket from its end. If what you want to do is have the .cgi program be able to send multiple requests to the server in one "session" (i.e. one user "submit" from the webpage) you should do something like have the .cgi send a "logoff" message to the server which causes it to tidy things up and flush the connection from its end.

Beware that the kind of think you're writing is fraught with danger and could cause lots of problems if someone ever hacked the protocol (not hard to do) unless you have authentication and encryption built into the client/server protocol.

Replies are listed 'Best First'.
RE: Re: Socket programming & CGI hell
by TQuid (Sexton) on Jul 19, 2000 at 22:29 UTC
    I believe this section does just what you've said:

    if ($command =~ /^BYE/) { print $new_sock "OK disconnecting . . . \n"; shutdown $new_sock, 2; exit 0; }

    Thanks for mentioning security--I should have mentioned, this will be happening inside an SSL-encrypted connection (and doubtless I'll be asking about Net::SSLeay on here soon). The server rejects any connections not coming from a small range currently, but encryption is indeed necessary before I can have anything like real security.

    --TQuid

      I'm less sure of what you're asking for now. Is your CGI sending multiple commands to the server in one session, but you are not seeing all of the returns from the commands until you close the session? If so you may look into adding some socket flushes to the server (and client) to flush the sockets after each "block" is ready to be sent. I generally use IO::Socket which has autoflush built into it by default.