server.js代码如下 var ws=require(‘websocket-server’);
var server=ws.createServer(); server.addListener('connection’,function(connection){ console.log(‘connected…’);
connection.addListener('message',function(msg){
console.log(msg);
});
});
server.listen(888); console.log(‘server start…’);
client.html代码如下
<html> <head> <title> Test WebSocket </title>
<script type="text/javascript"> var ws = new WebSocket("ws://127.0.0.1:888/");ws.onopen=function(){
document.write(‘hello’); } ws.onclose=function(){
document.write(‘close’); }
</script> </head> <body> </body> </html> **运行结果** server start.. connected.. 网页上居然输出:close。。 求解问题出现在哪儿了