Skip to content

Commit c482db3

Browse files
committed
update server talk
Change-Id: I8fb6195ad587ce828e6a0a189f15e88cb3306140
1 parent a69a422 commit c482db3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

content/socket.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ def runserver(host, port):
653653
try:
654654
readable, writeable, exceptional = select.select(inputs, outputs, [])
655655
for sock in readable:
656+
# client 连接
656657
if sock == s:
657658
clientsock, clientaddr = sock.accept()
658659
recvname = clientsock.recv(1024)
@@ -667,15 +668,18 @@ def runserver(host, port):
667668
for output in outputs:
668669
output.sendall("Welcome " + clientname + " Come In \n")
669670
outputs.append(clientsock)
670-
elif sock == 0:
671+
# server 说话
672+
elif sock == 0 or isinstance(sock, file):
671673
message = sys.stdin.readline()
672674
if message.startswith("QUIT"):
673675
print "Server is close ... "
674676
sys.exit(0)
675677
for output in outputs:
676678
output.sendall("Server : " + message)
679+
# server 接收数据
677680
else:
678681
data = sock.recv(1024)
682+
# 接收到数据就是有人说话
679683
if data:
680684
if data.startswith("SECRECT"):
681685
print "SECRECT " + clients[sock][0] + " : " + data,
@@ -689,6 +693,7 @@ def runserver(host, port):
689693
for output in outputs:
690694
if output != sock:
691695
output.sendall(clients[sock][0] + " : " + data)
696+
# 没接收到数据就是有人离开
692697
else:
693698
name = clients[sock][0]
694699
print name + " leaved "

0 commit comments

Comments
 (0)