在使用Iteratee的play-scala websocket中,我们如何将数据发送到websocket客户端功能?在进行频道推送之前,我们如何在scala中指定函数?
我当前的websocket服务器代码如下:
lazy val (out, channel) = Concurrent.broadcast[String] def connect = WebSocket.using[String] { request => val in = Iteratee.foreach[String] {
msg => println(msg)
channel push("I received your message: " + msg)
}
(in,out)
}
我目前的客户代码如下:
var ws = new WebSocket("ws://localhost:9000/connect.ws");
ws.onopen = function(){
console.log("Socket has been opened! ");
};
ws.onmessage = function(message) {
console.log(JSON.parse(message.data))
};
每次使用“频道推送”发送消息时,“ws.onmessage”都会被触发。如何在服务器端从客户端发出/触发自定义事件?
非常感谢你。