I am trying to make tic tac toe using websockets running on glassfish. I’ve download this example form git. Firstly, I want to test it, so I run it as a normal java process on my machine. I also made a tiny change to the 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');
}
and then
if (appType == "Mozilla") {
ws = new MozWebSocket(WEBSOCKET_URL);
//alert('MozWebSocket');
} else {
ws = new WebSocket(WEBSOCKET_URL);
//alert('WebSocket');
}
When I open the test page with FF 10.0 the event onclose is only invoked and I get the status “The WebSocket Connection Has Been Closed.” then I open the test page with Chrome 17.0.963.46 m. The status is also “The WebSocket….” but server throws an exception.
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)
What is the cause? I though about a few possilbe issues:
- I use Netty 3.2.6.Final from JBoss repository. It could use different standard of websockets than the browsers.
- running it as a java process on my machine istead as a webserver. But Netty doesn’t have any dependencies that would require it.
- Wrong locations. var WEBSOCKET_URL = “ws://localhost:9000/websocket”; and html location is C:…web\kolo\src\main\webapp\t.html
I am using Netbeans 7.1 and glassfish 3.1
Fixed project can be found https://github.com/lukasz-madon/Tic-Tac-Toe-with-WebSocket
I could be the web socket version. Here’s a table of web socket versions and which browser supports which.
From memory, 3.2.6 only supported HyBi-00.
Try Netty 3.3. It supports a number of versions.