问题描述
我无法在用Play!Framework 2.2创建的简单WebSocket应用中使用wss://
.它回显该消息.端点是这样的
I cannot use wss://
in my simple WebSocket app created with Play!Framework 2.2. It echoes the message back. The endpoint is like this
def indexWS2 = WebSocket.using[String] {
request => {
println("got connection to indexWS2")
var channel: Option[Concurrent.Channel[String]] = None
val outEnumerator: Enumerator[String] = Concurrent.unicast(c => channel = Some(c))
// Log events to the console
val myIteratee: Iteratee[String, Unit] = Iteratee.foreach[String] {gotString => {
println("received: " + gotString)
// send string back
channel.foreach(_.push("echoing back \"" + gotString + "\""))
}}
(myIteratee, outEnumerator)
}
}
,路线描述为
GET /ws2 controllers.Application.indexWS2
我从这样的JS客户端创建连接
I create a connection from a JS client like this
myWebSocket = new WebSocket("ws://localhost:9000/ws2");
,一切正常.但是,如果为了使用TLS将ws://
更改为wss://
,它将失败,并且出现以下Netty异常:
and everything works fine. But if I change ws://
into wss://
in order to use TLS, it fails and I get the following Netty exception:
[error] p.nettyException - Exception caught in Netty
java.lang.IllegalArgumentException: empty text
我该如何进行这项工作?谢谢.
How can I make this work? Thanks.
推荐答案
我真的很想为您解决这个问题!但是我不喜欢这个答案.似乎尚无针对Websocket的SSL的Play支持.在这里看到了它的提及,但自从没有任何进展的迹象: http ://grokbase.com/t/gg/play-framework/12cd53wst9/2-1-https-and-wss-secure-websocket-clarifications-and-documentation
I really wanted to figure this out for you! But I didn't like the answer. It appears there's no Play support yet for SSL for websockets. Saw mention of it here and no sign of progress since:http://grokbase.com/t/gg/play-framework/12cd53wst9/2-1-https-and-wss-secure-websocket-clarifications-and-documentation
但是,有希望!您可以将nginx用作安全的websocket(wss)终结点,以转发到具有不安全的websocket终结点的内部播放应用程序:
However, there's hope! You can use nginx as a secure websocket (wss) endpoint, to forward to a internal play app with a insecure websocket endpoint:
页面 http://siriux.net/2013/06/nginx-and -websockets/提供了以下说明以及用于nginx的示例代理配置:
The page http://siriux.net/2013/06/nginx-and-websockets/ provided this explanation and sample proxy config for nginx:
目标:WSS SSL端点:forwards wss|https://ws.example.com to ws|http://ws1.example.com:10080
Goal: WSS SSL Endpoint: forwards wss|https://ws.example.com to ws|http://ws1.example.com:10080
代理还是WSS和HTTPS连接的SSL端点.因此,客户端可以使用wss://连接(例如,通过HTTPS服务的页面),从而更适合损坏的代理服务器等."
"The proxy is also an SSL endpoint for WSS and HTTPS connections. So the clients can use wss:// connections (e.g. from pages served via HTTPS) which work better with broken proxy servers, etc."
server {
listen 443;
server_name ws.example.com;
ssl on;
ssl_certificate ws.example.com.bundle.crt;
ssl_certificate_key ws.example.com.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
# like above
}
}
Nginx非常轻巧有趣.会毫不犹豫地选择此选项.
Nginx is so lightweight and fun. Would not hesitate to go with this option.
这篇关于如何在Play!Framework WebSockets("wss://")中使用TLS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!