0

I'm trying to figure out exactly how to use web sockets and am having a little difficulty. I have one page where I dump a load of JSON data. I want to then create another page that establishes a web socket with the first page and pulls data from there. But, I can't quite seem to figure out how to communicate with another url via web sockets.

Any and all help would be greatly appreciated.

In my Controller class I have the page that gets the json defined by:

def sqlTest = Action {
    val json = Json.toJson(getData)
    Ok(json)
}

Then, I have my web socket defined as

def socket = WebSocket.accept[JsValue, JsValue] { request =>
    ActorFlow.actorRef(out => MyWebSocketActor.props(out))
}

Thanks in advance.

LivingRobot
  • 883
  • 2
  • 18
  • 34
  • "I want to then create another page that establishes a web socket with the first page and pulls data from there" ; what is that architecture? On every page load websocket connection is broken, when you land onto second page make a websocket connection and then push your data. and why do you need to make a websocket connection if you want to use data from your first url call, instead ok `Ok(json)` redirect it to new page with `json` data – curious Jun 16 '16 at 06:36
  • If it is direct communication from one browser to another browser that you are after then this is not possible: http://stackoverflow.com/questions/4277351/can-html5-websockets-connect-2-clients-browsers-directly-without-using-a-serve. – Kris Jun 16 '16 at 11:45
  • I have a server that's in communication with a database. The server pulls data through an HTTP request. Then, I have a client pulling data from the server. But, I would like for the client to pull data through a web socket so that there's a constant stream of data from server to client. Is that possible? – LivingRobot Jun 16 '16 at 14:57

0 Answers0