2
如何關閉WebSocket連接?如果您想立即關閉它,documentation上的示例有效。PlayFramework 2.2 scala關閉WebSocket連接
但是如何處理以下情況:我想在將來發生某種情況時關閉連接。例如,當我收到來自客戶的特定消息時。
def indexWS = WebSocket.using[String] {
request => {
var channel: Option[Concurrent.Channel[String]] = None
var outEnumerator: Enumerator[String] = Concurrent.unicast(c => channel = Some(c))
val myIteratee: Iteratee[String, Unit] = Iteratee.foreach[String] {gotString => {
// received a string from the client
if (gotString == "close_me") {
// outEnumerator = Enumerator.eof // doesn't work
// outEnumerator >>> Enumerator.eof // doesn't work
}
}}
(myIteratee, outEnumerator)
}
}
謝謝你的幫忙!