7

I try to use Tomcat implementation of WebSockets on local machine. When I use only tomcat everything works fine, but when I start use bundle Apache + mod_jk + Tomcat browser show me 'The connection to ws://example.com/test/echoMessage was interrupted while the page was loading' after couple of seconds of work. WebSocket connection is closed after this.

Can anyone tell me how to fix it?

I have: Apache HTTPD 2.2.18, mod_jk 1.2.37, Tomcat 7.0.28

Here is server side code that I use: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/ and client side: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/websocket/

Browsers: Firefox 12, Chrome 19

Mark
  • 71
  • 1
  • 3

1 Answers1

0

I would research whether Apache mod_proxy is able to transparently forward traffic at the TCP level at all. Since that is likely needed for WebSocket to pass through. IOW: is mod_proxy able to transparently reverse proxy WebSocket traffic?

But why would you want to bring Apache in the line anyway? It doesn't add any value, only more parts which can break. That is for WebSocket of course ..

oberstet
  • 21,353
  • 10
  • 64
  • 97
  • If you want to run a web server and WebSocket together on the same port then it makes perfect sense. And with the right configuration, WebSocket integration with Apache works just fine and there are several option including pywebsocket (which is specifically designed to do that). Easy integration with existing web servers was a big goal of the HyBi working group and the reason the WebSocket handshake is very HTTP-like. – kanaka Jun 29 '12 at 13:55
  • @oberstet I have working project which is written in Java(JSP/Servlets) and run on Tomcat with Apache in front. Apache is for static content(html, images and etc.) and SSL, and Tomcat is for dynamic content. Now I decide to add small websocket chat to it. If this chat won't work with Apache in front then I need to add new Tomcat or Jetty just for chat. This is not good idea. – Mark Jun 29 '12 at 14:58
  • @oberstet P.S. And of course this is not right way to use my existing Tomcat bypass Apache. – Mark Jun 29 '12 at 15:14
  • @kanaka: right, running on same host+port is indeed a reason (if thats wanted/needed). what is "the right configuration" for making Apache transparently reverse-proxy WS at the TCP level? do you have an example around or a link? – oberstet Jun 29 '12 at 16:10
  • @Mark: Technically, you can run WS on Tomcat on different port than the dynamic pages generated by Tomcat, and use Apache only to reverse-proxy the Web stuff, not the WS. Why is that "not right"? – oberstet Jun 29 '12 at 16:14
  • @oberstet, I don't have experience with transparent proxy of WebSocket via apache. I was answering your second point that there is no value to brining Apache in the line. Here is docs about using pywebsocket with Apache: http://code.google.com/p/pywebsocket/source/browse/trunk/src/mod_pywebsocket/__init__.py Here is a Clojure websockify implementation that uses Jetty for serving web requests and WebSocket requests on the same ports: https://github.com/kanaka/websockify/blob/master/other/websockify.clj – kanaka Jun 29 '12 at 17:16
  • @kanaka: Thanks for the pointers! FWIW: I guess the info needed for running Tomcat behind Apache is this: how to reverse-proxy WebSocket with Apache mod_proxy. pywebsocket is implemented as an Apache module, and hence can do any fancy stuff .. but won't help for Tomcat or similar situations. – oberstet Jun 29 '12 at 18:24
  • @oberstet Actually I didn't understand you completely. Apache work on 80 port. Tomcat by default on 8080. And there is option 'address=127.0.0.1' in config server.xml file. (http://tomcat.apache.org/tomcat-7.0-doc/config/http.html) It's mean that there is no access to port 8080 outside. So I really don't know how I can configure one Tomcat instance for work on two different ports on the same time. One (8080) for project and second one for websocket chat. Could you explain, please? – Mark Jun 30 '12 at 04:12
  • @Mark: I don't use Tomcat, but this seems to explain what to do: http://stackoverflow.com/questions/8823290/how-to-run-different-apps-on-single-tomcat-instance-behind-different-ports / Run your web app on port 8080 and websocket app on 8090. make 8080 proxied by apache and 8090 directly accessible from the outside. – oberstet Jun 30 '12 at 04:59