支持 js websocket
This commit is contained in:
18
examples/js_ws/index.js
Normal file
18
examples/js_ws/index.js
Normal file
@@ -0,0 +1,18 @@
|
||||
let ws = websocket();
|
||||
let shouldExit = false;
|
||||
while (!shouldExit) {
|
||||
let data = ws.readText();
|
||||
switch (data) {
|
||||
case "exit":
|
||||
shouldExit = true;
|
||||
break;
|
||||
case "panic":
|
||||
throw Error("错误");
|
||||
case "date":
|
||||
ws.writeText(new Date().toJSON())
|
||||
break
|
||||
default:
|
||||
ws.writeText("收到信息:" + data)
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user