Websockets in Java

The OpenShift forums have been retired.
You can still read and search them, but for help, please post a question on Stack Overflow.

I'm trying to use websockets in my Java app. I used diy app, installed Tomcat 7 on it - simple applications are deploying but i don't have any luck trying to do websockets (used 8000 port).

I installed Tomcat 7 on my own PC, and all seems to be working (including websockets).

Does anyone succesfully use java websockets on openshift?

Restrictions from this KB apply: https://www.openshift.com/kb/kb-e1038-i-cant-bind-to-a-port Please check it out.

@dopehate, it should work -- what's your app dns name ($app-$ns.rhcloud.com)?

Here's a sample application Tomcat7 application I just created and the websocket echo example
is at: http://tomcat7-ramr.rhcloud.com:8000/examples/websocket/echo.html

Quickstart+ instructions are on github: https://github.com/ramr/openshift-tomcat7-websockets

HTH

@ramr

I tried using your github Quickstart. My app is at http://tomcat7-riverwind.rhcloud.com/

Did exactly as readme said, and still experiencing troubles:

  1. http://tomcat7-riverwind.rhcloud.com:8000/ responds 302 - Moved Temporarily, and redirects me to https://openshift.redhat.com/app

  2. if you go to http://tomcat7-riverwind.rhcloud.com/examples/websocket/echo.html, press Messages or Streams and add 8000 to name (like ws://tomcat7-riverwind.rhcloud.com:8000/examples/websocket/echoStream) - respond is

Info: WebSocket connection opened.
Info: WebSocket connection closed.

It instantly closes after if opens.

@dopehate, hmm, works for me on node99 ... this looks to be a configuration issue (no routes)
on node18 where your gear is located. Will contact ops and check what's going on and update this thread.

Thanks for your patience.

@dopehate, this has now been fixed in production (routes weren't getting dynamically read/added).
Your app/the websockets example at:
http://tomcat7-riverwind.rhcloud.com:8000/examples/websocket/echo.html
works fine now.

Thanks for your patience.

I've just tested examples, and my own test app - all works fine!
Thank you a lot!

@ramr, I've exactly the same Problem. How did you solve it? Here is my Link to the websocket: http://test-trumpfstich.rhcloud.com/

Hi there, can i know how to make the websocket echo example work on openshift? I can't connect through the websocket, it closes automatically whenever i try to connect, any help? The error echo: https://fyp2013v3-weec0008.rhcloud.com/examples/websocket/echo.html

THanks Nam, previously I have refered to the website you mentioned, I have followed and tried with the port 8443 but it's still not working, still the same issue. Could that be the source of issue from server.xml? I followed this website: https://www.openshift.com/blogs/free-apache-tomcat-hosting-in-the-cloud-for-java-applications-its-called-openshift

Everything working well except websocket.

I have the same problem with the connection of the websocket. After connecting it closes immediately. I've read that there is someting with the routes-configuration. Has anyone a solution yet?

Here's a blog related to your issue that has some suggestions:
https://www.openshift.com/blogs/paas-websockets

Can you please take a look at it and see if it helps?

Hey, Thanks for your suggestion, but it still doesn't work. The port which i use is 8000.

It seems to be the same problem as dopehate had.

Any other help?

So just to be clear, your application should continue using port 8080 to serve (I'm currently getting a 503 which means the app is not reachable). Once your app is running, and you're getting responses on https://fyp2013v3-weec0008.rhcloud.com, then you can try the various different websocket ports from your client.

Reason being, there are a couple of proxies for you app. One which services normal http requests through https://fyp2013v3-weec0008.rhcloud.com (or http://fyp2013v3-weec0008.rhcloud.com) directed to your app running on http://$OPENSHIFT_INTERNAL_IP:$OPENSHIFT_INTERNAL_PORT, and the other is https://fyp2013v3-weec0008.rhcloud.com:8443 (or http://fyp2013v3-weec0008.rhcloud.com:8000) for websocket connections.

If either isn't responding, please let us know what errors you are getting in your logs: https://www.openshift.com/faq/how-to-troubleshoot-application-issues-using-logs

stefan commented on a thread in the OpenShift forum:

Hey, I also try to use tomcat with websockets. I installed it after this tutorial:
https://github.com/openshift/openshift-tomcat-quickstart [1]

Everything runs fine, except the websocket examples in tomcat. http://cat-trs.rhcloud.com:8000/examples/websocket/echo.html [2] Looks like dopehate had exactly the same kind of problem with the same
application. How did you solve that? Do I have to change something in tomcats config
files?

If you need some logfiles, just tell me where I can find it.

Some additional notes: - The tomcat websocket tutorial
https://github.com/ramr/openshift-tomcat7-websockets [3] is not working - You should mention in the rhc - application, that it is not possible to
create an app that is called "new"

@stefan, I'm checking with ops. Feel free to hop on IRC when you get a chance as well. We might need your help in resolving this (like uuid info and the like). When on, ping nduong.

@stefan, after reviewing http://cat-trs.rhcloud.com, looks like the routes are in place for your websocket connectivity. Seems the version of Tomcat may have issues. Can you try the latest (7.0.39) to see if that helps? There's been some bug fixes related to websockets since 7.0.29.

Thanks for your advice, I installed the latest version of tomcat. However, the issue remains. You can find the tomcat websocket example at: http://tomcat5-trs.rhcloud.com:8000/examples/websocket/echo.html

Here is my server.xml: http://pastebin.com/S8teUHWT

I installed tomcat in the /repo/diy/ directory. Logfiles seem to be ok so far.

Any other ideas about this?

Edit: Latest version of tomcat (7.0.39) now also at http://cat-trs.rhcloud.com

Thanks for the details. I'll reach need to reach out to a few folks on the details and get back to you.

I just gave the updated quickstart a try: https://github.com/ramr/openshift-tomcat7-websockets

After updating the .openshift/lib/utils to download version (tcversion="7.0.39"), it's working great. Thanks @ramr!!

Here's my URL (leaving it up for a couple days):
http://tomcatws-macdomain.rhcloud.com:8000/examples/websocket/echo.html

Thanks a lot, everything works fine now.