Python code demo -[ Python Network Socket ]
来源: BlogBus 原始链接: http://crquan.blogbus.com:80/s6344/index.html 存档链接: https://web.archive.org/web/20060211112412id_/http://crquan.blogbus.com:80/s6344/index.html
认真一点 Things have changed in the past two decades. / Top / 2005-12-08 12:47:10 Python code demo -[ Python Network Socket ] Python code demo def run( self ):
while 1:
Await an event on a readable socket descriptor
(sread, swrite, sexc) = select.select ( self.descriptors, [], [] )
Iterate through the tagged read descriptors
for sock in sread:
Received a connect to the server (listening) socket
if sock == self.srvsock: self.accept_new_connection() else:
Received something on a client socket
str = sock. recv (100)
Check to see if the peer socket closed
if str == '': host,port = sock. getpeername () str = 'Client left %s:%s\r\n' % (host, port) self.broadcast_string( str, sock ) sock. close self.descriptors.remove(sock) else: host,port = sock. getpeername () newstr = '[%s:%s] %s' % (host, port, str) self.broadcast_string( newstr, sock ) crquan Posted at 12:47:10 | Read More | Comment(1) | Reference Trackback(0) | Edit 2005-11-25 13:15:00 Policy Routing Using Linux -[ Network Linux ] Policy Routing Using Linux crquan Posted at 13:15:00 | Read More | Comment(0) | Reference Trackback(0) | Edit 2005-11-24 23:11:27 整天的 ping 啊: -[ ping Network ] 最近网络是经常断,于是有整天的 ping 啊: crquan Posted at 23:11:27 | Read More | Comment(0) | Reference Trackback(0) | Edit 2005-11-15 23:20:21 《Network ... Perl》 -[ Perl Network ] 不知何时,《Network Programming with Perl》...... crquan Posted at 23:20:21 | Read More | Comment(0) | Reference Trackback(1) | Edit PAGE: Some Zed Rank Cheng 深圳 南山 时间简史 Last Update Latest Comments Archieves Custom HTML My Favorite Links 访问统计: