H5 WebSocket
作者:
不语翕 | 来源:发表于
2017-11-09 18:05 被阅读0次<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function WebSocketTest(){
if("WebSocket" in window){
alert("WebSocket is supported by your Browser!");
var ws = new WebSocket("ws://localhost:9998/echo");
ws.onopen = function(){
ws.send("Message to send ");
alert("Message is sent...");
};
ws.onmessage = function(evt){
var received_msg = evt.data;
alert("Message is received...");
};
ws.onclose = function(){
alert("Connection is closed...");
};
}
else{
alert("WebSocket NOT supported by your Browser!");
}
}
</script>
</head>
<body>
<div id="sse">
<a href="javascript:WebSocketTest()">Run WebSocket</a>
</div>
</body>
</html>
本文标题:H5 WebSocket
本文链接:https://www.haomeiwen.com/subject/husmmxtx.html
网友评论