Skip to content

Commit 601d95f

Browse files
committed
chaneg some code in TCP server
1 parent 46210b9 commit 601d95f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

chapter16/TCP/TCPserver.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,43 @@
66
TCP时间戳服务器
77
"""
88

9+
"""
10+
改制poetry的测试结果
11+
12+
1.阻塞(block).
13+
14+
这个TCP服务器程序运行时,先后使用两次nc localhost port连接。
15+
在第一首诗歌没有发送完成时,阻塞。直到data ends,
16+
与第一个断开连接之后,才开始第二个连接发送。
17+
18+
waiting for connection
19+
('... connected from:', ('127.0.0.1', 41354))
20+
data ends
21+
waiting for connection
22+
('... connected from:', ('127.0.0.1', 41379))
23+
24+
2.对于客户端连接的检测.
25+
26+
tcpClisock, addr = tcpSocket.accept()
27+
这个函数会自身循环,一直到有客户端接入,将两个结果return之后,才进行下一句。
28+
所以这个检测客户端接入的过程不需要程序员手动写。
29+
30+
3.TODO.
31+
32+
程序ctrl-c之后无法自动回收端口
33+
客户端断开之后,socket.error: [Errno 32] Broken pipe
34+
35+
4.源程序改进(twisted/tw-into/block-server/slowpoetry)
36+
37+
main()中进行args的读取和socket的初始化,调用serve()完成工作
38+
一、把两层while的外层while做成serve()函数
39+
函数功能:
40+
1 判断接入并获取接入信息tcpSocket.accept()
41+
2 调用send_poetry()函数发送数据
42+
二、把内层函数抽象成发送诗歌信息的函数send_poetry()
43+
44+
"""
45+
946
from socket import *
1047
from time import ctime
1148

0 commit comments

Comments
 (0)