File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -229,13 +229,18 @@ Go语言中通过net包中的`DialTCP`函数来建立一个TCP连接,并返回
229
229
### 控制TCP连接
230
230
TCP有很多连接控制函数,我们平常用到比较多的有如下几个函数:
231
231
232
- #func (c *TCPConn) SetTimeout(nsec int64) os.Error
233
232
func DialTimeout(net, addr string, timeout time.Duration) (Conn, error)
234
- func (c *TCPConn) SetKeepAlive(keepalive bool) os.Error
235
233
236
- 第一个函数用来设置连接的超时时间,客户端和服务器端都适用,当超过设置的时间时该连接就会失效。
234
+ 设置建立连接的超时时间,客户端和服务器端都适用,当超过设置时间时,连接自动关闭。
235
+
236
+ func (c *TCPConn) SetReadDeadline(t time.Time) error
237
+ func (c *TCPConn) SetWriteDeadline(t time.Time) error
238
+
239
+ 用来设置写入/读取一个连接的超时时间。当超过设置时间时,连接自动关闭。
240
+
241
+ func (c *TCPConn) SetKeepAlive(keepalive bool) os.Error
237
242
238
- 第二个函数用来设置客户端是否和服务器端一直保持着连接,即使没有任何的数据发送 。
243
+ 设置客户端是否和服务器端保持长连接,可以降低建立TCP连接时的握手开销,对于一些需要频繁交换数据的应用场景比较适用 。
239
244
240
245
更多的内容请查看` net ` 包的文档。
241
246
## UDP Socket
You can’t perform that action at this time.
0 commit comments