Websockets and Java tutorial please


I’m looking at the java websockets tutorial, it’s a bit sad really


There is nothing usable about this page, it’s just a bunch of theory - important theory, sure, but still. Programming isn’t theory.

Can someone please update it to

  1. remove the weird link tip that points to https://www.websocket.org/echo.html ? I don’t understand… it has nothing to do with play.

  2. give some code that works with this javascript example here - https://www.tutorialspoint.com/html5/html5_websocket.htm so that people can actually use websockets locally

  3. explain and give code for the tip about same origins? It seems like a Very Important thing, and yet there is no code and its glossed over.

I like play, but the documentation is really really bad - i’d love to actually make the java doco much better, no idea how to!

1 Like

remove the weird link tip that points to […]? I don’t understand… it has nothing to do with play

It’s a javascript example, like your example code from tutorialspoint

For example, the field “Location” would be something like “ws://localhost:9000/mySocket”

Now, you are able to test your websocket API in Play. You can send a message and receive it by your websocket actor. That’s described in Handling WebSockets with actors

To use websockets, you must have basic knowledge about akka and actors.


i don’t have a lot of knowledge about this - does someone have a modern simple example of websockets working?

I found this on github - https://github.com/odadoda/SimpleChat/tree/master/conf - it’s great and simple, but it’s old and websockets in play has moved on it seems.

I really just want a basic example, once i’ve seen how the thing “works” i can jump to more complicated examples. The main play java example on github is a full-throated chat thing, i don’t need to see everything working though, just a subset.

Hi @bharal, there are sample applications in Java and Scala:

  1. https://github.com/playframework/play-scala-websocket-example
  2. https://github.com/playframework/play-java-websocket-example

While these are not tutorials, they could be useful to complement the documentation you already read.

1 Like

Also, https://github.com/playframework/play-socket.io for socket-io is available that need a bit more love in the documentation. Socket-io is the way that most front-end developers use WebSockets these days. In many modern front-end frameworks, when you google WebSocket the first thing you will get is Socket-io plugins. The Play-Socket.io has couple of examples that is useful.

1 Like

You can edit the documentation by clicking on this link.

You can edit the text on that web page, and submit a pull request and it will go through testing etc. It’s a good way to get started with Play. :slight_smile:


Also if anyone wants to enhance our docs by adding links to some of these examples then I think that would be helpful for the community. :smile:


If you are interested in the play-socket.io library, helping with the documentation and examples there would be a great way to get involved. At the moment it’s not really officially maintained, though I think it is used internally at Lightbend.

1 Like



These might help to give an idea, unfortunately none of them which are recent


looking at the play-websocket io, but I cannot seem to get the example working. I can get a new room & a leave room message, sure, but the “chat” message just doesn’t flow through.

Is something wrong with the example? I’m looking at the multi-room one (not clustered)