我正在用Java编写WebSocket服务器.当我使用WebSocket连接到firefox中的服务器时,我发现建立了两个连接,其中一个从未发送任何数据...
我的firefox版本是15.0.1
在Chrome中运行的相同代码是OK,连接一次,建立只有一个连接.
有人有这样的麻烦吗?
有服务器的代码:
ServerSocket svrSock = new ServerSocket();
svrSock.bind(new InetSocketAddress("0.0.0.0", 11111));
while(true) {
try {
// accept connection
Socket clientSock = svrSock.accept();
// print the socket which connected to this server
System.out.println("accept socket: " + clientSock);
// run a thread for client
new ClientThread(clientSock).start();
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
还有js代码:
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!');
};
Run Code Online (Sandbox Code Playgroud)
当我在firefox中运行这个js代码时,我在服务器控制台中得到了这个:
accept socket:Socket [addr …