node.js中ws模块创建服务端和客户端,网页WebSocket客户端

2020-06-17 05:58:37易采站长站整理

var ws = new WebSocket("ws://127.0.0.1:6080/index.html");
ws.onopen = function(){
alert("open");
ws.send("WebSocket hellowrold!!");
};
ws.onmessage = function(ev){
alert(ev.data);
};
ws.onclose = function(ev){
alert("close");
};
ws.onerror = function(ev){
console.log(ev);
alert("error");
};
</script>
</body>
</html>

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对软件开发网的支持。如果你想了解更多相关内容请查看下面相关链接