## WebSocket and Comet support through Socket.IO Scalatra provides optional support for websockets and comet through [socket.io](http://socket.io). We depend on [the socketio-java project](http://code.google.com/p/socketio-java) to provide this support. 1. Depend on the scalatra-socketio.jar. In your SBT build: val scalatraSocketIO = "org.scalatra" % "scalatra-socketio" % scalatraVersion 2. SocketIO mimics a socket connection so it's easiest if you just create a socketio servlet at /socket.io/* import org.scalatra.ScalatraServlet import org.scalatra.socketio.SocketIOSupport class MySocketIOServlet extends ScalatraServlet with SocketIOSupport { // ... } 3. Setup the callbacks socketio { socket => socket.onConnect { connection => // Do stuff on connection } socket.onMessage { (connection, frameType, message) => // Receive a message // use `connection.send("string")` to send a message // use `connection.broadcast("to send")` to send a message to all connected clients except the current one // use `connection.disconnect` to disconnect the client. } socket.onDisconnect { (connection, reason, message) => // Do stuff on disconnection } } 4. Add the necessary entries to web.xml <servlet> <servlet-name>SocketIOServlet</servlet-name> <servlet-class>com.example.SocketIOServlet</servlet-class> <init-param> <param-name>flashPolicyServerHost</param-name> <param-value>localhost</param-value> </init-param> <init-param> <param-name>flashPolicyServerPort</param-name> <param-value>843</param-value> </init-param> <init-param> <param-name>flashPolicyDomain</param-name> <param-value>localhost</param-value> </init-param> <init-param> <param-name>flashPolicyPorts</param-name> <param-value>8080</param-value> </init-param> </servlet> When you want to use websockets with jetty the sbt build tool gets in the way and that makes it look like the websocket stuff isn't working. If you deploy the war to a jetty distribution everything should work as expected.