@@ -256,7 +256,7 @@ Go语言中通过net包中的`DialTCP`函数来建立一个TCP连接,并返回
256
256
257
257
func handleClient(conn net.Conn) {
258
258
conn.SetReadDeadline(time.Now().Add(2 * time.Minute)) // set 2 minutes timeout
259
- request := make([]byte, 128) // set maxium request length to 128KB to prevent flood attack
259
+ request := make([]byte, 128) // set maxium request length to 128B to prevent flood attack
260
260
defer conn.Close() // close connection before exit
261
261
for {
262
262
read_len, err := conn.Read(request)
@@ -273,7 +273,7 @@ Go语言中通过net包中的`DialTCP`函数来建立一个TCP连接,并返回
273
273
conn.Write([]byte(daytime))
274
274
} else {
275
275
daytime := time.Now().String()
276
- conn.Write([]byte(daytime))
276
+ conn.Write([]byte(daytime))
277
277
}
278
278
279
279
request = make([]byte, 128) // clear last read content
@@ -298,7 +298,7 @@ TCP有很多连接控制函数,我们平常用到比较多的有如下几个
298
298
299
299
func (c *TCPConn) SetReadDeadline(t time.Time) error
300
300
func (c *TCPConn) SetWriteDeadline(t time.Time) error
301
-
301
+
302
302
用来设置写入/读取一个连接的超时时间。当超过设置时间时,连接自动关闭。
303
303
304
304
func (c *TCPConn) SetKeepAlive(keepalive bool) os.Error
@@ -312,7 +312,7 @@ Go语言包中处理UDP Socket和TCP Socket不同的地方就是在服务器端
312
312
func ResolveUDPAddr(net, addr string) (*UDPAddr, os.Error)
313
313
func DialUDP(net string, laddr, raddr *UDPAddr) (c *UDPConn, err os.Error)
314
314
func ListenUDP(net string, laddr *UDPAddr) (c *UDPConn, err os.Error)
315
- func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err os.Error
315
+ func (c *UDPConn) ReadFromUDP(b []byte) (n int, addr *UDPAddr, err os.Error)
316
316
func (c *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (n int, err os.Error)
317
317
318
318
一个UDP的客户端代码如下所示,我们可以看到不同的就是TCP换成了UDP而已:
0 commit comments