File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 6
6
TCP时间戳服务器
7
7
"""
8
8
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
+
9
46
from socket import *
10
47
from time import ctime
11
48
You can’t perform that action at this time.
0 commit comments