python socket server ²¢·¢£¨×ª£©
import SocketServer, time, select, sys
from threading import Thread
COMMAND_HELLO = 1
COMMAND_QUIT = 2
# The SimpleRequestHandler class uses this to parse command lines.
class SimpleCommandProcessor:
def __init__(self):
pass
def process(self, line, request):
"""Process a command"""
args = line.split(' ')
command = args[0].lower()
args = args[1:]
if command == 'hello':
request.send('HELLO TO YOU TO!\n\r')
return COMMAND_HELLO
elif command == 'quit':
request.send('OK, SEE YOU LATER\n\r')
return COMMAND_QUIT
else:
request.send('Unknown command: "%s"\n\r' % command)
# SimpleServer extends the TCPServer, using the threading mix in
# to create a new thread for every request.
class SimpleServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
# This means the main server will not do the equivalent of a
# pthread_join() on the new threads. With this set, Ctrl-C will
# kill the server reliably.
daemon_threads = True
# By setting this we allow the server to re-bind to the address by
# setting SO_REUSEADDR, meaning you don't have to wait for
# timeouts when you kill the server and the sockets don't get
 
Ïà¹ØÎĵµ£º
ʹÓà Python ·ÖÀëÖÐÎÄÓëÓ¢ÎĵĻìºÏ×Ö´®
LiYanrui
posted @ ´óÔ¼ 1 Äêǰ
in ³ÌÐòÉè¼Æ
with tags
python
, 614 ÔĶÁ
Õâ¸öÎÊÌâÊÇ×ö MkIV Ô¤´¦Àí³ÌÐò
ʱ¸ã¶¨µÄ£¬¾ÍÊǰÑÒ»¸ö»ìºÏÁËÖÐÓ¢ÎÄ»ìºÏ×Ö´®·ÖÀëΪӢÎÄÓëÖÐÎĵÄ×Ó×Ö´®£¬Æ©È磬½« ”ÎÒµÄ English ѧµÄ²»ºÃ
&ld ......
"""A parser for HTML and XHTML."""
# This file is based on sgmllib.py, but the API is slightly different.
# XXX There should be a way to distinguish between PCDATA (parsed
# character data -- the normal case), RCDATA (replaceable character
# data -- only char and entity references and end tags a ......
from http://blog.alexa-pro.cn/?p=349
ÄÚÈݸÅÒª:Python´úÂë¼ÓÃÜ,Ô´Âë±£»¤,´úÂë±£»¤,pycÎļþ
------------------------------------------------
¹ØÓÚpython´úÂë±£»¤ÔÚÍøÉϺÃÏñһֱûÓкܺõĽéÉÜ,¿ÉÄܺÍPYTHONµÄÉè¼Æ³õÖÔ"¿ªÔ´"ÓйØ,µ«Ô½À´Ô½¶àµÄÐÖµÜдµÄ¼ÓÈëPYTHONÕóÓª,¿ª·¢¹¤¾ßÓÃ;¸÷Òì,ÔÚÉÌÒµÓ¦ÓÃÖдúÂë± ......
ÍøÂç³ô³æÒà¼´ÍøÂçÐű꣬ÊÇͨ¹ýijÖÖÊÖ¶ÎÒþʽ»ñÈ¡ÐÅÏ¢µÄµÄ·½·¨¡£
ÔÚbottle frameworkÖпÉÓÃÏÂÃæµÄ·½·¨ÊµÏÖ£º
Ê×ÏÈÔÚÄãÒªÓû§ä¯ÀÀÆ÷ÏÔʾµÄÒ³ÃætplÉÏǶÈëÒ»¸ö1*1ÏñËØµÄͼƬ£¬»ò¸üС¡£
Õâ¸öͼƬµØÖ·Ö¸ÏòÄã·þÎñÆ÷ÉÏij¸öÌØ¶¨Î»Öã¬Èçstatic/webtrack.png¡£
Óû§´ò¿ªÍøÒ³£¬¾Í»á·ÃÎÊÕâ¸öͼƬ£¨Í¨¹ýä¯ÀÀÆ÷Èçhttp://abc.abc.com/st ......