You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Alexander Farber <al...@gmail.com> on 2010/03/01 09:57:21 UTC

HTTP Streaming with Apache 1

Hello,

I have a game, a daemon listening at port 8080 for TCP clients.
The clients send auth. details with each their message and
I keep the state, so the TCP-connection can be interrupted
and then reconnected and the game will still continue.

To support players behind corporate firewalls :-) I've written a simple
Apache module, which will listen for client requests at the port 80,
then read that POST request in, then connect to port 8080 and
forward that data. Then it will stay connected to both ports and
forward data from the game daemon to the web client:

I want it to stay connected and "stream HTTP data" back, so that
I can update the web clients instantly, when something changes.

Perfect solution would be to poll() at the both sockets (80 and 8080)
and forward the data in both directions. But unfortunately this
isn't possible with Apache 1 (would it work with Apache 2?
Can I get ahold of the client socket there and can I poll() it?)

So I try the other trick: when the web client needs to send
a new asynchronous message to the game daemon,
I cancel the previous connection (unfortunately the Apache
module doesn't notice that, because it is blocking while reading
from the port 8080 socket) and also in the game daemon
I take the notice, that a new message has arrived from the same
user and close the port 8080 socket to the old Apache module.

Unfortunately this works only few times and then I hit the max.
children limitation of Apache (I've set it to 10 at my debug server)
and Apache refuses to accept further connections.

I'm using Apache 1.3.x of OpenBSD 4.5 and the source code
of my Apache module is at http://pastebin.com/FvnXieN7

Does anybody have any good comments?

Thank you
Alex


PS: And my (Russian card) game is at
       http://apps.facebook.com/video-preferans/  :-)

Re: HTTP Streaming with Apache 1

Posted by Alexander Farber <al...@gmail.com>.
OpenBSD's Apache 1.3.x is compiled with EAPI.
Is there a way to access the client socket then,
so that I can select() or poll() on it?

Does anybody please have a hint here?

Regards
Alex

On Mon, Mar 1, 2010 at 9:57 AM, Alexander Farber
<al...@gmail.com> wrote:
>
> Perfect solution would be to poll() at the both sockets (80 and 8080)
> and forward the data in both directions. But unfortunately this
> isn't possible with Apache 1 (would it work with Apache 2?
> Can I get ahold of the client socket there and can I poll() it?)
>
> So I try the other trick: when the web client needs to send
> a new asynchronous message to the game daemon,
> I cancel the previous connection (unfortunately the Apache
> module doesn't notice that, because it is blocking while reading
> from the port 8080 socket) and also in the game daemon
> I take the notice, that a new message has arrived from the same
> user and close the port 8080 socket to the old Apache module.
>
> Unfortunately this works only few times and then I hit the max.
> children limitation of Apache (I've set it to 10 at my debug server)
> and Apache refuses to accept further connections.
>
> I'm using Apache 1.3.x of OpenBSD 4.5 and the source code
> of my Apache module is at http://pastebin.com/FvnXieN7

Re: HTTP Streaming with Apache 1

Posted by Ben Noordhuis <in...@bnoordhuis.nl>.
> I wonder if it's possible with Apache 2?
> To get hold of the client socket, so that I can poll()
> or select() it and implement server push aka Comet

r->connection->cs->pfd.desc.s->socketdes if I'm not mistaken. Check
out apr_pollset_create() if you are going to do polling inside Apache
or sendmsg(2) if you want to pass the fd to another process.

Re: HTTP Streaming with Apache 1

Posted by Alexander Farber <al...@gmail.com>.
Hello Ray,

On Tue, Mar 2, 2010 Ray Morris <su...@bettercgi.com> wrote:
>   I don't know how to help you with the method you're
> trying to use, but I may be able to help achieve your
> goal simply and efficiently.  For a similar situation,
> I just forwarded port 80 to port 8080 via the the firewall.

thanks, but I think it's not the same.

1) Most companies have some kind of filtering web
proxies at the port 80 (and all other ports blocked) -
like Squid or commercial ones (NetCache?)
and this just won't work.

2) And also I already have Apache at the port 80,
serving my site. OpenBSD's or Linux firewall
won't be able to selectively redirect requests
(unless I write some pf module for that).

I wonder if it's possible with Apache 2?
To get hold of the client socket, so that I can poll()
or select() it and implement server push aka Comet

Regards
Alex