Delving into the world of webSockets, Angular, and Play framework has been a rewarding journey so far. I've been utilizing https://github.com/AngularClass/angular-websocket for seamless integration with Angular. The connection setup like this:
var dataStream = $websocket('wss://echo.websocket.org/');
runs smoothly. However, attempting to connect to:
var dataStream = $websocket('wss://localhost:9000/socket');
leads to the following error:
WebSocket connection to 'wss://localhost:9000/socket' failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED
The logs from Play/Netty only show:
play.core.server.netty.PlayDefaultUpstreamHandler - Exception caught in Netty
java.lang.IllegalArgumentException: empty text
This is the code snippet used on the backend:
def socket = WebSocket.acceptWithActor[String, String] { request => out =>
MyWebSocketActor.props(out)
}
object MyWebSocketActor {
def props(out: ActorRef) = Props(new MyWebSocketActor(out))
}
class MyWebSocketActor(out: ActorRef) extends Actor {
def receive = {
case msg: String =>
out ! ("I received your message: " + msg)
}
}
(taken from: )
You can view my code here: https://github.com/dataplayground/playground/blob/master/public/javascripts/main.js