fix KB -> B
This commit is contained in:
@@ -256,7 +256,7 @@ Go语言中通过net包中的`DialTCP`函数来建立一个TCP连接,并返回
|
|||||||
|
|
||||||
func handleClient(conn net.Conn) {
|
func handleClient(conn net.Conn) {
|
||||||
conn.SetReadDeadline(time.Now().Add(2 * time.Minute)) // set 2 minutes timeout
|
conn.SetReadDeadline(time.Now().Add(2 * time.Minute)) // set 2 minutes timeout
|
||||||
request := make([]byte, 128) // set maxium request length to 128KB to prevent flood attack
|
request := make([]byte, 128) // set maxium request length to 128B to prevent flood attack
|
||||||
defer conn.Close() // close connection before exit
|
defer conn.Close() // close connection before exit
|
||||||
for {
|
for {
|
||||||
read_len, err := conn.Read(request)
|
read_len, err := conn.Read(request)
|
||||||
@@ -273,7 +273,7 @@ Go语言中通过net包中的`DialTCP`函数来建立一个TCP连接,并返回
|
|||||||
conn.Write([]byte(daytime))
|
conn.Write([]byte(daytime))
|
||||||
} else {
|
} else {
|
||||||
daytime := time.Now().String()
|
daytime := time.Now().String()
|
||||||
conn.Write([]byte(daytime))
|
conn.Write([]byte(daytime))
|
||||||
}
|
}
|
||||||
|
|
||||||
request = make([]byte, 128) // clear last read content
|
request = make([]byte, 128) // clear last read content
|
||||||
@@ -298,7 +298,7 @@ TCP有很多连接控制函数,我们平常用到比较多的有如下几个
|
|||||||
|
|
||||||
func (c *TCPConn) SetReadDeadline(t time.Time) error
|
func (c *TCPConn) SetReadDeadline(t time.Time) error
|
||||||
func (c *TCPConn) SetWriteDeadline(t time.Time) error
|
func (c *TCPConn) SetWriteDeadline(t time.Time) error
|
||||||
|
|
||||||
用来设置写入/读取一个连接的超时时间。当超过设置时间时,连接自动关闭。
|
用来设置写入/读取一个连接的超时时间。当超过设置时间时,连接自动关闭。
|
||||||
|
|
||||||
func (c *TCPConn) SetKeepAlive(keepalive bool) os.Error
|
func (c *TCPConn) SetKeepAlive(keepalive bool) os.Error
|
||||||
|
|||||||
Reference in New Issue
Block a user