How to send and receive WebSocket messages with Play Framework?

129 views
Skip to first unread message

Jonas

unread,
Oct 27, 2011, 1:30:45 PM10/27/11
to play-framework
I implemented an WebSocketController
http://www.playframework.org/documentation/1.2.3/asynchronous#UsingWebSockets
, similar to the one in the Play Framework tutorial, but it doesn't
receive any messages from the client. Have I done anything wrong?

Here is my WebSocketController:

public class TestSocket extends WebSocketController {

public static void hello(String name) {
while(inbound.isOpen()) {
WebSocketEvent evt = await(inbound.nextEvent());
if(evt instanceof WebSocketFrame) {
WebSocketFrame frame = (WebSocketFrame)evt;
System.out.println("received: " + frame.getTextData());
if(!frame.isBinary()) {
if(frame.getTextData().equals("quit")) {
outbound.send("Bye!");
disconnect();
} else {
outbound.send("Echo: %s", frame.getTextData());
}
}
} else if(evt instanceof WebSocketClose) {
System.out.println("socket closed");
}
}
}
}

I have also posted this question on StackOverflow, including a client:
http://stackoverflow.com/questions/7919856/how-to-use-websockets-with-play-framework

Jonas

unread,
Oct 28, 2011, 4:11:06 AM10/28/11
to play-framework
The problem was that I imported
org.jboss.netty.handler.codec.http.websocket.WebSocketFrame instead of
play.mvc.Http.WebSocketFrame

Peter Hilton - committer (Lunatech)

unread,
Oct 28, 2011, 8:55:12 AM10/28/11
to play-fr...@googlegroups.com
If you want to see another example, have a look at the progress bar demo in the jQuery UI module:

Helena Hjertén

unread,
Oct 28, 2011, 9:08:38 AM10/28/11
to play-fr...@googlegroups.com
Tried to clone the jqueryui module: 

Cloning into jqueryui-module...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

What am I doing wrong?
/Helena




2011/10/28 Peter Hilton - committer (Lunatech) <peter....@gmail.com>
If you want to see another example, have a look at the progress bar demo in the jQuery UI module:

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/TtCT2VsKswYJ.

To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Peter Hilton - committer (Lunatech)

unread,
Oct 28, 2011, 9:21:34 AM10/28/11
to play-fr...@googlegroups.com
I’m not sure, did you do the following command?

Also, I should have mentioned that the web socket controller is:

Helena Hjertén

unread,
Oct 28, 2011, 10:38:59 AM10/28/11
to play-fr...@googlegroups.com
I followed your instructions in the README:
git clone g...@github.com:hilton/jqueryui-module.git
BUT, I tried using the https link as below, and then in worked fine...

Thanks, 
/Helena


2011/10/28 Peter Hilton - committer (Lunatech) <peter....@gmail.com>
I’m not sure, did you do the following command?

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/rISIh_oSotUJ.

Peter Hilton - committer (Lunatech)

unread,
Oct 31, 2011, 6:31:17 AM10/31/11
to play-fr...@googlegroups.com
Ah, good point. I’ve fixed the README and docs now. Thanks.
Reply all
Reply to author
Forward
0 new messages