Skip to content

Commit 427deef

Browse files
author
Anchor
committed
Fix sentence flow and grammar for 08.2.md [en]
1 parent 4e8894f commit 427deef

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

en/eBook/08.2.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
# 8.2 WebSocket
1+
# 8.2 WebSockets
22

3-
WebSocket is an important feature of HTML5, it implemented remote socket based on browsers, which allows browsers have full-duplex communication with servers. Main stream browsers like Firefox, Google Chrome and Safari have supported this feature.
3+
WebSockets are an important feature of HTML5. It implements browser based remote sockets, which allows browsers to have full-duplex communications with servers. Main stream browsers like Firefox, Google Chrome and Safari provide support for this WebSockets.
44

5-
People often use "roll poling" for instant message services before WebSocket was born, which let clients send HTTP requests in every certain period, then server returns latest data to clients. This requires clients to keep sending a lot of requests and take up a large number of bandwidth.
5+
People often used "roll polling" for instant messaging services before WebSockets were born, which allow clients to send HTTP requests periodically. The server then returns the latest data to clients. The downside to this method is that it requires clients to keep sending many requests to the server, which can consume a large amount of bandwidth.
66

7-
WebSocket uses a kind of special header to reduce handshake action between browsers and servers to only once, and create a connection. This connection will remain active, you can use JavaScript to write or read data from this the connection, as in the use of a conventional TCP socket. It solves the problem of web real-time development, and has following advantages over traditional HTTP:
7+
WebSockets use a special kind of header that reduces the number of handshakes required between browser and server to only one, for establishing a connection. This connection will remain active throughout its lifetime, and you can use JavaScript to write or read data from this connection, as in the case of a conventional TCP sockets. It solves many of the headache involved with real-time web development, and has the following advantages over traditional HTTP:
88

9-
- Only one TCP connection for a singe web client.
9+
- Only one TCP connection for a single web client.
1010
- WebSocket servers can push data to web clients.
11-
- More lightweight header to reduce data transmission.
11+
- Lightweight header to reduce data transmission overhead.
1212

13-
WebSocket URL starts with ws:// or wss://(SSL). The following picture shows the communication process of WebSocket, where a particular HTTP header was sent to server for handshake, then servers or clients are able to send or receive data through JavaScript according to some kind of socket, this socket can be used by the event handler to receive data asynchronously.
13+
WebSocket URLs begin with ws:// or wss://(SSL). The following figure shows the communication process of WebSockets. A particular HTTP header is sent to the server as part of the handshaking protocol and the connection is established. Then, servers or clients are able to send or receive data through JavaScript via WebSocket. This socket can then be used by an event handler to receive data asynchronously.
1414

1515
![](images/8.2.websocket.png?raw=true)
1616

17-
Figure 8.2 WebSocket principle.
17+
Figure 8.2 WebSocket principl
1818

19-
## WebSocket principle
19+
## WebSocket principles
2020

21-
WebSocket protocol is quite simple, after the adoption of the first handshake, the connection is established successfully. Subsequent communication data are all begin with "\x00" and ends with "\xFF". Clients will not see these two parts because WebSocket will break off both ends and gives raw data automatically.
21+
The WebSocket protocol is actually quite simple. After successfully completing the initial handshake, a connection is established. Subsequent data communications will all begin with "\x00" and end with "\xFF". This prefix and suffix will be visible to clients because the WebSocket will break off both end, yielding the raw data automatically.
2222

23-
WebSocket connection are requested by browsers and responded by servers, then the connection is established, this process is often called "handshake".
23+
WebSocket connections are requested by browsers and responded to by servers, after which the connection is established. This process is often called "handshaking".
2424

25-
Consider the following requests and feedback:
25+
Consider the following requests and responses:
2626

2727
![](images/8.2.websocket2.png?raw=true)
2828

2929
Figure 8.3 WebSocket request and response.
3030

31-
"Sec-WebSocket-key" is generated randomly, as you may guess, this is encoded by base64. Servers need to append this key to a fixed string after accepted:
31+
"Sec-WebSocket-key" is generated randomly, as you may have already guessed, and it's base64 encoded. Servers need to append this key to a fixed string after accepting a request:
3232

3333
258EAFA5-E914-47DA-95CA-C5AB0DC85B11
3434

3535
Suppose we have `f7cb4ezEAl6C3wRaU6JORA==`, then we have:
3636

3737
f7cb4ezEAl6C3wRaU6JORA==258EAFA5-E914-47DA-95CA-C5AB0DC85B11
3838

39-
Use sha1 to compute binary value and use base64 to encode it, then we have:
39+
Use sha1 to compute the binary value and use base64 to encode it. We will then we have:
4040

4141
rE91AJhfC+6JdVcVXOGJEADEJdQ=
4242

43-
Use this as value of `Sec-WebSocket-Accept` for respond header.
43+
Use this as the value of the `Sec-WebSocket-Accept` response header.
4444

4545
## WebSocket in Go
4646

47-
Go standard library does not support WebSocket, but package `websocket`, which is the sub-package of `go.net` and maintained by official support it.
47+
The Go standard library does not support WebSockets. However the `websocket` package, which is a sub-package of `go.net` does, and is officially maintained and supported.
4848

4949
Use `go get` to install this package:
5050

5151
go get code.google.com/p/go.net/websocket
5252

53-
WebSocket has client and server sides, let's see a simple example: user input information, client sends content to server through WebSocket; server pushes information back up client.
53+
WebSockets have both client and server sides. Let's see a simple example where a user inputs some information on the client side and sends it to the server through a WebSocket, followed by the server pushing information back to the client.
5454

5555
Client code:
5656

@@ -95,12 +95,12 @@ Client code:
9595
</body>
9696
</html>
9797

98-
As you can see, JavaScript is very easy to write in client side, and use corresponding function establish a connection. Event `onopen` triggered after handshake to tell client that connection was created successfully. Client bindings four events:
98+
As you can see, it's very easy to use the client side JavaScript functions to establish a connection. The `onopen` event gets triggered after successfully completing the aforementioned handshaking process. It tells the client that the connection has been created successfully. Clients attempting to open a connection typically bind to four events:
9999

100-
- 1)onopen: triggered after connection was established.
101-
- 2)onmessage: triggered after received message.
102-
- 3)onerror: triggered after error occurred.
103-
- 4)onclose: triggered after connection closed.
100+
- 1)onopen: triggered after connection has been established.
101+
- 2)onmessage: triggered after receiving a message.
102+
- 3)onerror: triggered after an error has occurred..
103+
- 4)onclose: triggered after the connection has closed.
104104

105105
Server code:
106106

@@ -144,13 +144,13 @@ Server code:
144144
}
145145
}
146146

147-
When client `Send` user input information, server `Receive` it, and use `Send` to return feedback.
147+
When a client `Send`s user input information, the server `Receive`s it, and uses `Send` once again to return a response.
148148

149149
![](images/8.2.websocket3.png?raw=true)
150150

151151
Figure 8.4 WebSocket server received information.
152152

153-
Through the example above we see that the client and server side implementation of WebSocket are very convenient. We can use package `net` directly in Go. Now with rapid develop of HTML5, I think WebSocket will be much more important in web development, we need to reserve this knowledge.
153+
Through the example above, we can see that the client and server side implementation of WebSockets is very convenient. We can use the `net` package directly in Go. With the rapid development of HTML5, I think that WebSockets will take on a much more important role in modern day web development; we should all be at least a little bit familiar with them.
154154

155155
## Links
156156

0 commit comments

Comments
 (0)