You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 5-network/11-websocket/article.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ let socket = new WebSocket("*!*ws*/!*://javascript.info");
19
19
20
20
`ws://`를 사용해 데이터를 전송하면 데이터가 암호화되어있지 않은 채로 전송되기 때문에 데이터가 그대로 노출됩니다. 그런데 아주 오래된 프락시 서버는 웹소켓이 무엇인지 몰라서 '이상한' 헤더가 붙은 요청이 들어왔다고 판단하고 연결을 끊어버립니다.
21
21
22
-
반면 `wss://`는 TSL(전송 계층 보안(Transport Layer Security))이라는 보안 계층을 통과해 전달되므로 송신자 측에서 데이터가 암호화되고, 복호화는 수신자 측에서 이뤄지게 됩니다. 따라서 데이터가 담긴 패킷이 암호화된 상태로 프락시 서버를 통과하므로 프락시 서버는 패킷 내부를 볼 수 없게 됩니다.
22
+
반면 `wss://`는 TSL(전송 계층 보안(Transport Layer Security))이라는 보안 계층을 통과해 전달되므로 송신자 측에서 데이터가 암호화되고, 복호화는 수신자 측에서 이뤄지게 됩니다. 따라서 데이터가 담긴 패킷이 암호화된 상태로 프락시 서버를 통과하므로 프락시 서버는 패킷 내부를 볼 수 없게 됩니다.
-`code` is a special WebSocket closing code (optional)
222
222
-`reason` is a string that describes the reason of closing (optional)
223
223
224
-
Then the other party in `close` event handler gets the code and the reason, e.g.:
224
+
Then the other party in the `close` event handler gets the code and the reason, e.g.:
225
225
226
226
```js
227
227
// closing party:
@@ -249,7 +249,7 @@ There are other codes like:
249
249
250
250
The full list can be found in [RFC6455, §7.4.1](https://tools.ietf.org/html/rfc6455#section-7.4.1).
251
251
252
-
WebSocket codes are somewhat like HTTP codes, but different. In particular, any codes less than `1000` are reserved, there'll be an error if we try to set such a code.
252
+
WebSocket codes are somewhat like HTTP codes, but different. In particular, codes lower than `1000` are reserved, there'll be an error if we try to set such a code.
253
253
254
254
```js
255
255
// in case connection is broken
@@ -321,8 +321,8 @@ Server-side code is a little bit beyond our scope. Here we'll use Node.js, but y
321
321
The server-side algorithm will be:
322
322
323
323
1. Create `clients = new Set()` -- a set of sockets.
324
-
2. For each accepted websocket, add it to the set `clients.add(socket)` and setup`message` event listener to get its messages.
325
-
3. When a message received: iterate over clients and send it to everyone.
324
+
2. For each accepted websocket, add it to the set `clients.add(socket)` and set`message` event listener to get its messages.
325
+
3. When a message is received: iterate over clients and send it to everyone.
326
326
4. When a connection is closed: `clients.delete(socket)`.
327
327
328
328
```js
@@ -359,7 +359,7 @@ Here's the working example:
359
359
360
360
[iframe src="chat" height="100" zip]
361
361
362
-
You can also download it (upper-right button in the iframe) and run locally. Just don't forget to install [Node.js](https://nodejs.org/en/) and `npm install ws` before running.
362
+
You can also download it (upper-right button in the iframe) and run it locally. Just don't forget to install [Node.js](https://nodejs.org/en/) and `npm install ws` before running.
363
363
364
364
## Summary
365
365
@@ -383,6 +383,6 @@ Events:
383
383
384
384
WebSocket by itself does not include reconnection, authentication and many other high-level mechanisms. So there are client/server libraries for that, and it's also possible to implement these capabilities manually.
385
385
386
-
Sometimes, to integrate WebSocket into existing project, people run WebSocket server in parallel with the main HTTP-server, and they share a single database. Requests to WebSocket use `wss://ws.site.com`, a subdomain that leads to WebSocket server, while `https://site.com` goes to the main HTTP-server.
386
+
Sometimes, to integrate WebSocket into existing projects, people run a WebSocket server in parallel with the main HTTP-server, and they share a single database. Requests to WebSocket use `wss://ws.site.com`, a subdomain that leads to the WebSocket server, while `https://site.com` goes to the main HTTP-server.
387
387
388
388
Surely, other ways of integration are also possible.
0 commit comments