Skip to content

Commit 4f37163

Browse files
committed
Merge branch 'master' into gitpractice
2 parents e228576 + ad6470c commit 4f37163

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

5-network/11-websocket/article.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
# WebSocket
1+
# 웹소켓
22

33
The `WebSocket` protocol, described in the specification [RFC 6455](http://tools.ietf.org/html/rfc6455) provides a way to exchange data between browser and server via a persistent connection. The data can be passed in both directions as "packets", without breaking the connection and additional HTTP-requests.
44

5-
WebSocket is especially great for services that require continuous data exchange, e.g. online games, real-time trading systems and so on.
5+
이런 특징 때문에 웹소켓은 온라인 게임이나 주식 트레이딩 시스템같이 데이터 교환이 지속적으로 이뤄져야 하는 서비스에 아주 적합합니다.
66

77
## A simple example
88

9-
To open a websocket connection, we need to create `new WebSocket` using the special protocol `ws` in the url:
9+
웹소켓 연결을 만들려면 `new WebSocket`을 호출하면 되는데, 이때 `ws`라는 특수 프로토콜을 사용합니다.
1010

1111
```js
1212
let socket = new WebSocket("*!*ws*/!*://javascript.info");
1313
```
1414

15-
There's also encrypted `wss://` protocol. It's like HTTPS for websockets.
15+
`ws`말고 `wss://`라는 프로토콜도 있는데, 두 프로토콜의 관계는 HTTP와 HTTPS의 관계와 유사하다고 보시면 됩니다.
1616

17-
```smart header="Always prefer `wss://`"
17+
```smart header="항상 `wss://`를 사용합시다."
1818
The `wss://` protocol is not only encrypted, but also more reliable.
1919

2020
That's because `ws://` data is not encrypted, visible for any intermediary. Old proxy servers do not know about WebSocket, they may see "strange" headers and abort the connection.
2121

22-
On the other hand, `wss://` is WebSocket over TLS, (same as HTTPS is HTTP over TLS), the transport security layer encrypts the data at sender and decrypts at the receiver. So data packets are passed encrypted through proxies. They can't see what's inside and let them through.
22+
반면 `wss://`는 TSL(전송 계층 보안(Transport Layer Security))이라는 보안 계층을 통과해 전달되므로 송신자 측에서 데이터가 암호화되고, 복호화는 수신자 측에서 이뤄지게 됩니다. 따라서 데이터가 담긴 패킷은 암호화된 상태로 프락시 서버를 통과하므로 프락시 서버는 패킷 내부를 볼 수 없게 됩니다.
2323
```
2424
2525
Once the socket is created, we should listen to events on it. There are totally 4 events:
26-
- **`open`** -- connection established,
26+
- **`open`** -- 커넥션이 제대로 만들어짐
2727
- **`message`** -- data received,
2828
- **`error`** -- websocket error,
29-
- **`close`** -- connection closed.
29+
- **`close`** -- 커넥션 종료
3030
31-
...And if we'd like to send something, then `socket.send(data)` will do that.
31+
커넥션이 만들어진 상태에서 무언가를 보내고 싶으면 `socket.send(data)`를 사용하면 됩니다.
3232
33-
Here's an example:
33+
예시를 살펴봅시다.
3434
3535
```js run
3636
let socket = new WebSocket("wss://javascript.info/article/websocket/demo/hello");
3737
3838
socket.onopen = function(e) {
39-
alert("[open] Connection established");
39+
alert("[open] 커넥션이 만들어졌습니다.");
4040
alert("데이터를 서버에 전송해봅시다.");
4141
socket.send("My name is John");
4242
};
4343
4444
socket.onmessage = function(event) {
45-
alert(`[message] Data received from server: ${event.data}`);
45+
alert(`[message] 서버로부터 전송받은 데이터: ${event.data}`);
4646
};
4747
4848
socket.onclose = function(event) {
4949
if (event.wasClean) {
50-
alert(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
50+
alert(`[close] 커넥션이 정상적으로 종료되었습니다(code=${event.code} reason=${event.reason})`);
5151
} else {
52-
// e.g. server process killed or network down
52+
// 예시: 프로세스가 죽거나 네트워크에 장애가 있는 경우
5353
// event.code is usually 1006 in this case
54-
alert('[close] Connection died');
54+
alert('[close] 커넥션이 죽었습니다.');
5555
}
5656
};
5757
@@ -60,15 +60,15 @@ socket.onerror = function(error) {
6060
};
6161
```
6262

63-
For demo purposes, there's a small server [server.js](demo/server.js) written in Node.js, for the example above, running. It responds with "Hello from server, John", then waits 5 seconds and closes the connection.
63+
위 예시는 데모 목적을 위해 만들어놓은 작은 Node.js 서버([server.js](demo/server.js))에서 돌아갑니다. 이 서버는 'Hello from server, John'이라는 메시지가 담긴 응답을 보내고, 5초 후 커넥션을 종료시킵니다.
6464

65-
So you'll see events `open` -> `message` -> `close`.
65+
서버에 작성한 코드가 동작하면서 `open` -> `message` -> `close` 순의 이벤트를 볼 수 있었던 것이죠.
6666

6767
That's actually it, we can talk WebSocket already. Quite simple, isn't it?
6868

69-
Now let's talk more in-depth.
69+
그렇긴 하지만 실무 수준에서 웹소켓을 활용할 수 있도록 웹소켓에 대해 좀 더 자세하게 알아봅시다.
7070

71-
## Opening a websocket
71+
## 웹소켓 열기
7272

7373
When `new WebSocket(url)` is created, it starts connecting immediately.
7474

0 commit comments

Comments
 (0)