Skip to content

Commit f88a41b

Browse files
committed
fixes
1 parent e52705e commit f88a41b

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

5-network/11-websocket/article.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ Here's an example:
3636
let socket = new WebSocket("wss://javascript.info/article/websocket/demo/hello");
3737
3838
socket.onopen = function(e) {
39-
alert("[open] Connection established, send the data -> server");
39+
alert("[open] Connection established");
40+
alert("Sending to server");
4041
socket.send("My name is John");
4142
};
4243
4344
socket.onmessage = function(event) {
44-
alert(`[message] Data received: ${event.data} <- server`);
45+
alert(`[message] Data received from server: ${event.data}`);
4546
};
4647
4748
socket.onclose = function(event) {

5-network/11-websocket/demo.view/server.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ function accept(req, res) {
99
res.end();
1010
return;
1111
}
12+
1213
// can be Connection: keep-alive, Upgrade
13-
if (req.headers.connection.match(/\bupgrade\b/i)) {
14+
if (!req.headers.connection.match(/\bupgrade\b/i)) {
1415
res.end();
1516
return;
1617
}
@@ -20,8 +21,8 @@ function accept(req, res) {
2021

2122
function onConnect(ws) {
2223
ws.on('message', function (message) {
23-
let name = message.match(/\w+$/) || "Guest";
24-
ws.send(`Hello, ${name}!`);
24+
let name = message.match(/([\p{Alpha}\p{M}\p{Nd}\p{Pc}\p{Join_C}]+)$/gu) || "Guest";
25+
ws.send(`Hello from server, ${name}!`);
2526

2627
setTimeout(() => ws.close(1000, "Bye!"), 5000);
2728
});

5-network/11-websocket/websocket-handshake.svg

Lines changed: 11 additions & 11 deletions
Loading

figures.sketch

12.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)