disconnect / apache-websocket

Apache WebSocket module
Apache License 2.0
196 stars 46 forks source link

Connection Closed #16

Open ghost opened 12 years ago

ghost commented 12 years ago

Noobish, my apologies,

Software: Ubuntu 11.04, Apache2 2.2.17, Firefox 12, Chromium 18.

Steps:

  1. "sudo scons install" from within your github "Download.zip" extracted folder/files (not "pulled" via github, is there a difference?)
  2. step 1 locates files in the /usr/lib/apache2/modules directory
  3. Symbolic links in the /etc/apache2/mods-enabled directory matching the mods-available directory (websocket.load & websocket_draft76.load
  4. "sudo scons install" from within your "examples" directory; loads files into /usr/lib/apache2/modules directory with no errors (mod_websocket_echo.* & mod_websocket_dumb_increment.* files)
  5. Restarting Apache: a). "sudo apache2ctl restart" says it loads successfully...but, b). "sudo /etc/init.d/apache2 restart" fails with: Permission denied: make_sock: could not bind to address 127.0.0.1:80 no listening sockets available, shutting down Unable to open logs c). No log files to give more information.
  6. Launching client.html in either browser generates an immediate "Connection Closed" response.

Notes: I am using your httpd.conf for ubuntu:

LoadModule websocket_module   /usr/lib/apache2/modules/mod_websocket.so
LoadModule websocket_draft76_module   /usr/lib/apache2/modules/mod_websocket_draft76.so

<IfModule mod_websocket.c>
  <Location /echo>
    SetHandler websocket-handler
    WebSocketHandler /usr/lib/apache2/modules/mod_websocket_echo.so echo_init
 </Location>
</IfModule>

<IfModule mod_websocket_draft76.c>
  <Location /echo>
    SetHandler websocket-handler
    WebSocketHandler /usr/lib/apache2/modules/mod_websocket_echo.so echo_init
    SupportDraft75 On
  </Location>
</IfModule>

The client.html is at var/www/client.html with : www-data (group) and 777 permissions, and I have also tried root : root with 755

The virtual directive for default is

<VirtualHost 127.0.0.1>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel debug

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        # Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

Can you advise on why I am only getting "Connection Closed" in the browser and the "Permission denied when restarting using the sudo /etc/init.d/apache2 restart command?

ghost commented 12 years ago

I got both examples working but not by the methods stated, which I am sure is my mistake. I would like to know why it is...

First, I made corrections to the default VirtualHosts tags: changing the VirtualHosts tags from VirtualHost 127.0.0.1 to VirtualHost :80 Second, I had to make a similar change in the ports.conf, changing to: NameVirtualHost :80 and Listen 80 Third, I was then able to run both the echo and dumb-increment examples BUT ONLY if I copied their respective file contents into "var/www/index.html" Fourth, I changed the httpd.conf file to read:

LoadModule websocket_module   /usr/lib/apache2/modules/mod_websocket.so
LoadModule websocket_draft76_module   /usr/lib/apache2/modules/mod_websocket_draft76.so
<IfModule mod_websocket.c>
  <Location /echo>
    SetHandler websocket-handler
    WebSocketHandler /usr/lib/apache2/modules/mod_websocket_echo.so echo_init
  </Location>
  <Location /dumb-increment>
    SetHandler websocket-handler
    WebSocketHandler /usr/lib/apache2/modules/mod_websocket_dumb_increment.so dumb_increment_init
  </Location>
</IfModule>

<IfModule mod_websocket_draft76.c>
  <Location /echo>
    SetHandler websocket-handler
    WebSocketHandler /usr/lib/apache2/modules/mod_websocket_echo.so echo_init
    SupportDraft75 On
  </Location>
  <Location /dumb-increment>
    SetHandler websocket-handler
    WebSocketHandler /usr/lib/apache2/modules/mod_websocket_dumb_increment.so dumb_increment_init
    SupportDraft75 On
  </Location>
</IfModule>

My understanding is that if I placed the client.html and the increment.html files within var/www/echo/client.html and var/www/dumb-increment/increment.html then I would be able to browse to http://localhost/echo/client.html and http://localhost/dumb-increment/increment.html to see them work, but that never worked. When I did that, the apache2 error logs gave a 301 error (permanently moved).

Obviously, I am misunderstanding something simple. If the answer is too complex for your time, can you advise on what I should be reading up on? (Thanks.)

disconnect commented 12 years ago

I can't speak much for the virtual host issues, but you should be able to put client.html and increment.html into var/www/ and then just access using http://localhost/client.html and http://localhost/increment.html. The /echo and /dumb-increment references are just a way of matching a handler to a path contained in a WebSocket request. Don't try to load your HTML file from there.

As for starting/stopping apache, I always use "sudo apachectl restart".

ghost commented 12 years ago

I apologize for missing the obvious, perhaps my ignorance will help others in the future. Thanks.

BTW, I have the same issue now as #8, disconnecting after about 10 seconds. Is the only solution to this issue what he had done (changing the RequestReadTimeout)?

Finally, I had read a post from the guy who owns "pusher" and a few others who tend to claim that Apache is not a good or reliable server for WebSockets. That would be pretty bad if it's true as I see WebSockets as coming on strong in the near future. Have you heard more about Apache implementing your code? You seem to have the only solution for making WebSockets work in Apache.

Thanks for your work.

disconnect commented 12 years ago

For now, use the RequestReadTimeout to workaround the timeout issue.

I had an interest in using WebSockets and was locked in to using an Apache server, so I created the module. I haven't seen the "pusher" guy's claim about Apache. However, from my own experience, I haven't had any problems with it. It has been very reliable for me, and it gets the job done.

Hawkin commented 11 years ago

I have the same problem, the connection is closed after 10-11 seconds, in both examples. It's very strange, cause the server seems to work perfectly, sending the numbers well. Let me explain. I ran the page and the numbers came without problem. If a click 'Reset' before the 10 seconds, the 'Reset' is correctly processed in the server, and the coount restart at 0, sending the numbers correctly. And continues receiving the numbers to the infinite (well, I didn't wait till infinite) but if I clicked 'Reset' (after 10 seconds from the page load), the connections came closed.

I saw the event raised in javascript, and is more strange cause it said it's a clean close:

bubbles: false
cancelBubble: false
cancelable: false
clipboardData: undefined
code: 1000
currentTarget: WebSocket
defaultPrevented: false
eventPhase: 0
reason: ""
returnValue: true
srcElement: WebSocket
target: WebSocket
timeStamp: 1363015161151
type: "close"
wasClean: true

Websockets seems to be the best option for realtime solutions but it's not usable with a timeout. I can send you any information you need.

Thanks for the great job.

i-am-steve commented 8 years ago

I ran into the timeout issue too, and found that setting the timeout value to 0 apparently keeps the connection open forever.

This is what I put in my httpd.conf: RequestReadTimeout body=0,minrate=500

And now the connection stays open for many hours.