2012-02-19 59 views
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); 
} 

是握手響應錯了嗎?我怎樣才能解決這個問題?

回答

2

嘗試從主分支獲取最新版本。 1.2.4在最新版本的websockets協議發佈之前發佈。因此,自從瀏覽器添加新版本以來,這一直是一個移動的目標,並且Web服務器也試圖趕上。

現在應該是穩定的,因爲它已經成爲W3C的標準,Websocket支持直接來自Netty,而不是來自Play本身。

+0

完美的工作。謝謝! – user1219646 2012-02-19 20:48:23