0
我想设置一个简单的Websockets服务器与播放!框架(1.2.4)。所有现在应该发生的事情是客户端应该连接,收到“Hello User”消息,然后套接字应该关闭。我得到不同浏览器的不同结果:Safari按预期工作;铬17使一个错误:玩!框架Websockets与Chrome 17
play.exceptions.JavaExecutionException: The outbound channel is closed
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at play.mvc.WebSocketInvoker.invoke(WebSocketInvoker.java:28)
at play.server.PlayHandler$WebSocketInvocation.execute(PlayHandler.java:1332)
...
这里是服务器端代码:
package controllers;
import play.*;
import play.mvc.*;
import play.mvc.Http.WebSocketClose;
import play.mvc.Http.WebSocketEvent;
import play.mvc.Http.WebSocketFrame;
import java.util.*;
import models.*;
import play.data.validation.*;
public class Application extends Controller {
public static void index() {
render();
}
public static class WebSocket extends WebSocketController {
public static void hello(String name) {
outbound.send("Hello %s!", name);
}
}
}
/WS被路由到Application.WebSocket.hello。 客户端JavaScript:
window.onload = function() {
document.getElementById('sendbutton')
.addEventListener('click', sendMessage, false);
document.getElementById('connectbutton')
.addEventListener('click', connect, false);
document.getElementById('disconnectbutton')
.addEventListener('click', disconnect, false);
}
function writeStatus(message) {
var html = document.createElement("div");
html.setAttribute('class', 'message');
html.innerHTML = message;
document.getElementById("status").appendChild(html);
}
function connect() {
ws = new WebSocket("ws://localhost:9000/ws?name=User");
ws.onopen = function(evt) {
writeStatus("connected");
}
ws.onclose = function(evt) {
writeStatus("disconnected");
}
ws.onmessage = function(evt) {
writeStatus("response: " + evt.data);
}
ws.onerror = function(evt) {
writeStatus("error: " + evt.data);
}
}
function disconnect() {
ws.close();
}
function sendMessage() {
ws.send(document.getElementById('messagefield').value);
}
是握手响应错了吗?我怎样才能解决这个问题?
完美的工作。谢谢! – user1219646 2012-02-19 20:48:23