我正在尝试使用在glassfish上运行的websockets来制作tic tac toe。我已经下载了this example表格git。首先,我想测试它,所以我在我的机器上将其作为普通的java进程运行。我也对tictacto.js进行了微小的改动
if (typeof MozWebSocket != "undefined") { // (window.MozWebSocket)
appType = "Mozilla";
} else if (window.WebSocket) {
appType = "Chrome";
} else {
alert('ERROR: This browser does not support WebSockets');
}
然后
if (appType == "Mozilla") {
ws = new MozWebSocket(WEBSOCKET_URL);
//alert('MozWebSocket');
} else {
ws = new WebSocket(WEBSOCKET_URL);
//alert('WebSocket');
}
当我使用FF 10.0打开测试页时,仅调用onclose事件并且我获得状态“WebSocket连接已关闭”。然后我用Chrome 17.0.963.46 m打开测试页面。状态也是“WebSocket ....”但服务器抛出异常。
run:
TicTacToe Server: Listening on port 9000
java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:218)
at sun.nio.ch.IOUtil.read(IOUtil.java:186)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:359)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:323)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:282)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:202)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
原因是什么?我虽然有几个可能的问题:
我正在使用Netbeans 7.1和glassfish 3.1
可以找到固定项目 https://github.com/lukasz-madon/Tic-Tac-Toe-with-WebSocket