I am encoding a WebSocket server in Java. When I use WebSocket to connect to the server in firefox, I find that two connections are established, and one of them never sends any data ...
My version of firefox is 15.0.1
The same code that runs in Chrome is fine, Once connected, established only one connection.
Does anyone have such problems?
There is a server code:
ServerSocket svrSock = new ServerSocket();
svrSock.bind(new InetSocketAddress("0.0.0.0", 11111));
while(true) {
try {
Socket clientSock = svrSock.accept();
System.out.println("accept socket: " + clientSock);
new ClientThread(clientSock).start();
} catch (Exception e) {
e.printStackTrace();
}
}
And there is js code:
var url = 'ws://localhost:11111/test/';
var ws = new WebSocket(url);
ws.onopen = function(){
console.log('connected!');
ws.send(11111);
ws.close();
};
ws.onclose = function(){
console.log('closed!');
};
When I run this js code in firefox, I get this on my server console:
accept socket: Socket [addr = / 127.0.0.1, port = 56935, localport = 11111]
accept socket: Socket [addr = / 127.0.0.1, port = 56936, localport = 11111]