Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy Tomcat's example websocket applications?

I am trying understand how to deploy the examples referenced in the Apache Tomcat 7 WebSocket How-To page.

The Application Development section advises reading javadoc on WebSocketServlet class. But looking at the server side code of the examples, none of the classes in the three examples extend WebSocketServlet, which is what I had expected it to do.

I am returning to servlet development after over a decade and feeling quite lost with all the annotations in these examples. Is there another How-To that has step-by-step simple instructions for getting a WebSocket using servlet up and running?

like image 224
Miserable Variable Avatar asked Mar 15 '13 23:03

Miserable Variable


1 Answers

When you download the distribution of Apache Tomcat (7.0.37 is the latest version at the moment), you will have the examples web application already deployed. It comes with the WebSocket Examples. You don't have to deploy it yourself.

Start Tomcat and open http://localhost:8080/examples.

Apache Tomcat Examples

Click WebSocket Examples and pick whatever WebSocket example you want.

Apache Tomcat WebSocket Examples

You don't have to do anything other than to start Tomcat with bin/catalina.sh run (or whatever command works for you).

When you look into [TOMCAT_HOME]/webapps/examples directory, you may want to look at WEB-INF/web.xml where you see the WebSocket servlets deployed.

Their source code is in [TOMCAT_HOME]/WEB-INF/classes/websocket directory.

The servlet websocket.echo.EchoMessage does extend org.apache.catalina.websocket.WebSocketServlet.

I wonder if I should have asked you about the version of Apache Tomcat you use? Perhaps you use some other not-so-recent version? I recommend to start with the latest version as it worked fine for me.

like image 194
Jacek Laskowski Avatar answered Nov 18 '22 12:11

Jacek Laskowski