scala - Play Framework 2.3 and javascript websocket client library -
i have installed new play framework 2.3 scala 2.11, , build application websocket.
the server scala in quite simple code:
object testwebsocket extends controller { def mysocketservice = websocket.acceptwithactor[string, string] { request => out => testsocketactor.props(out) } }
the route.conf is: /wsk/testwebsocket controllers.testwebsocket.mysocketservice
now need javascript code connect page scala code, javascript library can use? have seen socket.io, seems work node.js server.
i know can use websocket directly, using library socket.io compatibility old browser.
can me? thank much
try out javascript. standard way on chrome, safari, mozilla etc.
<script type="text/javascript"> function websockettest(){ if ("websocket" in window){ var ws = new websocket("@routes.controllers.testwebsocket.mysocketservice().websocketurl()"); ws.onopen = function(){ // web socket connected, send data using send() console.log("connected"); ws.send("message send"); }; ws.onmessage = function (evt){ var received_msg = evt.data; console.log(evt.data); }; ws.onclose = function(){ // websocket closed. alert("connection closed..."); }; }else{ // browser doesn't support websocket alert("websocket not supported browser!"); } } websockettest(); </script>
let me know how goes.
Comments
Post a Comment