2012-02-19 7 views
0

나는 플레이!로 간단한 웹 소켓 서버를 설정하려고합니다. 프레임 워크 (1.2.4). 이제는 클라이언트가 연결하고 "Hello User"메시지를받은 다음 소켓을 닫아야한다는 것입니다. 브라우저마다 다른 결과가 나타납니다. Safari는 예상대로 작동합니다. 여기재생! 프레임 워크 웹 소켓과 크롬 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) 
... 

를 서버 측 코드 : 크롬 17은 에러가 발생

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로 라우팅된다. 클라이언트 측 자바 스크립트 :

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

master 분기에서 최신 버전을 가져 오십시오. 1.2.4는 웹 소켓 프로토콜의 최신 버전이 발표되기 전에 릴리스되었습니다. 결과적으로, 브라우저가 최신 버전을 추가하고 웹 서버가 따라 잡으려고 시도하면서, 이것은 계속 움직이는 목표였습니다.

이것은 이제 W3C의 표준이되어 안정적이어야하며 Websocket 지원은 Play 자체가 아니라 Netty에서 직접 지원됩니다.

+0

완벽하게 작동했습니다. 고맙습니다! – user1219646