Python--简单的多线程服务端
时间:2011-02-19 来源:Freall
1 #!/usr/bin/python
2
3 import socket
4 import thread
5
6 s = socket.socket()
7 s.bind(('127.0.0.1',1234))
8 s.listen(10)
9
10
11 def process(cs,address):
12 print 'From:',address
13 cs.send('hello,I am server')
14
15 flag = True
16 while flag:
17 ra = cs.recv(512)
18 print '%s say %s ' % (address,ra)
19 if ra == 'quit':
20 cs.close()
21 s.close()
22 print '%s Quit...' % address
23 flag = False
24
25 while True:
26 cs,address = s.accept()
27 if cs != None:
28 thread.start_new_thread(process,(cs,address))
29
相关阅读 更多 +