Merge pull request #551 from haibin/master

Update 08.1 en
This commit is contained in:
astaxie
2015-10-24 04:01:34 +08:00

View File

@@ -42,7 +42,7 @@ The `net` package in Go provides many types, functions and methods for network p
type IP []byte
Functions `ParseIP(s string) IP` is for converting an IP from the IPv4 format into IPv6:
Function `ParseIP(s string) IP` is to convert the IPv4 or IPv6 format to an IP:
package main
import (
@@ -297,7 +297,7 @@ Some of you may be thinking the following: this server does not do anything mean
}
}
In this example, we use `conn.Read()` to constantly read client requests. We cannot close the connection because clients may issue more than one request. Due to the timeout we set using `conn.SetReadDeadline()`, the connection closes automatically when a client has not sent a request within our allotted time period. When then expiry time has elapsed, our program breaks from the `for` loop. Notice that `request` needs to be created with a max size limitation in order to prevent flood attacks. FInally, we clean the `request` array after processing every request, since `conn.Read()` appends new content to the array instead of rewriting it.
In this example, we use `conn.Read()` to constantly read client requests. We cannot close the connection because clients may issue more than one request. Due to the timeout we set using `conn.SetReadDeadline()`, the connection closes automatically when a client has not sent a request within our allotted time period. When then expiry time has elapsed, our program breaks from the `for` loop. Notice that `request` needs to be created with a max size limitation in order to prevent flood attacks. Finally, we clean the `request` array after processing every request, since `conn.Read()` appends new content to the array instead of rewriting it.
### Controlling TCP connections