Skip to content

Instantly share code, notes, and snippets.

@snailsmall612
Created May 22, 2022 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snailsmall612/8b1997c3a9b3458e79511385c6aafcd2 to your computer and use it in GitHub Desktop.
Save snailsmall612/8b1997c3a9b3458e79511385c6aafcd2 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>WebSocket test</title>
<script>
var ws = new WebSocket("ws://localhost:9502");
ws.onopen = function(event) {
console.log("客户端已連接上!");
ws.send("hello server, this is client!"); //client to server message
};
ws.onmessage = function(event) {
console.log("server message: " + event.data);
}
ws.onclose = function(event) {
console.log("連接已關閉");
};
</script>
</head>
<body>
WebSocket test
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment