Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

PythonÖÐreactor,factory,protocolµÄѧϰ±Ê¼Ç


PythonÖÐreactor,factory,protocolµÄѧϰ±Ê¼Ç
 
 
×îΪ¼òµ¥µÄÇé¿öÏ£¬³ýÁËÁ˽âÇåreactorµÄ¼òµ¥Ê¹Óã¬Ä㻹ҪÁ˽âProtocolºÍFactory¡£ËüÃÇ×îÖÕ¶¼»áÓÉreactorµÄÕìÌý½¨Á¢ºÍrunÀ´Í³Ò»µ÷¶ÈÆðÀ´¡£    
   
     ½¨Á¢·þÎñÆ÷µÄµÚÒ»¸öÒª½â¾öµÄÎÊÌâ¾ÍÊÇ·þÎñÓëÍâ½çµÄ½»Á÷ЭÒ顣ЭÒéµÄ¶¨ÒåÔÚtwistedÖÐÊÇͨ¹ý¼Ì³Ðtwisted.internet.protocol.ProtocolÀàÀ´ÊµÏֵġ£ÔÚЭÒéÖÐÄã¿ÉÒÔ¶¨ÒåÁ¬½Ó¡¢Êý¾Ý½ÓÊÕ¡¢¶Ï¿ªÁ¬½ÓµÈһϵÁеÄʼþÈç¹û½øÐÐÏìÓ¦¡£µ«ÊǶÔÓÚËùÓÐÁ¬½ÓÉÏÀ´µÄЭÒéµÄ½¨Á¢¡¢³Ö¾ÃÅäÖÃÊý¾ÝµÄ´æ´¢ÕâÑùµÄÄÚÈݲ¢²»»á±£´æÔÚЭÒéÖС£    
   
  ³Ö¾ÃÅäÖÃÊý¾ÝµÄ´æ´¢Í¨³£¶¼»á±£´æÔÚ¹¤³§Àï¡£    
   
     ¹¤³§µÄ¶¨ÒåÔÚtwistedÖÐÊÇͨ¹ý¼Ì³Ðtwisted.internet.protocol.FactoryÀàÀ´ÊµÏֵġ£twistedÌṩÁËȱʡµÄ¹¤³§ÊµÏÖ×îΪÆÕͨµÄÐèÇó¡£Ëü»áʵÀý»¯Ã¿¸öЭÒ飬²¢ÇÒͨ¹ýÉèÖÃÿ¸öЭÒéÖÐfactoryÊôÐÔÀ´Ê¹Ð­Òé¿ÉÒÔʹÓõ½Ëü×Ô¼º£¬×öÕâ¸öÉèÖõÄ×÷ÓþÍÊÇÈÃЭÒéÔÚ½øÐд¦ÀíÁ¬½ÓÊý¾Ýʱ¿ÉÒÔʹÓõ½¹¤³§Öд洢µÄ³Ö¾ÃÅäÖÃÊý¾Ý¡£¹¤³§µÄÆô¶¯ÊÇÐèÒªreactorÕæʵµÄ½¨Á¢ÕìÌý²¢Æô¶¯²Å¿ÉÒÔʵÏֵġ£    
   
    reactorÕìÌýµÄ½¨Á¢¿ÉÒԲο¼   twisted.internet.interfaces.IReactorTCP.listenTCP¡£ÕâʱÎÒÃÇÏÈֻ˵½¨Á¢TCP·þÎñÆ÷µÄÕìÌý£¬Èç¹ûÄãÐèÒªÆäËüÖÖÀàµÄÕìÌý½¨Á¢²Î¿¼IReactor*.listen*ϵÁÐAPI¡£    
   
  ×ܽáһϣ¬ÎÒÃÇÊéдһ¸ötwistedµÄDaemon£¬ÊµÖÊÉÏ»á¹Ø×¢Èý¸ö²ã´ÎµÄ¶ÔÏó¡£ËüÃÇ»¥Ïà¿ÉÅäÖ㬿ɶÀÁ¢¿ª·¢£¬Ö»ÐèҪͨ¹ý¼òµ¥µÄµ÷ÓÃÅäÖþͿɽáºÏʹÓᣵÚÒ»²ã´Î¾ÍÊÇÕìÌýµÄ½¨Á¢¡¢¹¤³§µÄ³õʼ»¯¡¢·þÎñÆ÷µÄÔËÐУ¬ËüÐèÒªreactorµÄ¿ª·¢¡£µÚ¶þ¸ö²ã´Î¾ÍÊÇ·þÎñµÄ³õʼ»¯¡¢Óû§Á¬½ÓµÄ½¨Á¢¡¢³Ö¾ÃÅäÖÃÊý¾ÝµÄ´æ´¢¡¢Ð­ÒéµÄʵÀý»¯£¬ËüÐèÒªfactoryµÄ¿ª·¢¡£µÚÈý¸ö²ã´Î¾ÍÊÇÓû§Á¬½Ó½¨Á¢ºóµÄʼþ´¦Àí£¬Õâ¾ÍÐèÒªprotocolµÄ¿ª·¢ÁË¡£    
-------------------------------------------------------------------------------------------------------------------------
ÉÏÃæÊÇÒýÓñðÈ˵Ļ°£¬ÏÂÃæÊÇ×Ô¼ºµÄѧϰ£º
 
Ò»¡¢
protocol£ºÄÚ²¿ÊµÏÖµÄÖ÷ÒªÊÇÁ¬½ÓÔÚͨÐÅʱµÄ¶¯×÷£»
         ÄÚ²¿ÓÐtransport£¬¿É½øÐÐwrite(), getpeer()(host,port)
 &


Ïà¹ØÎĵµ£º

ÓÃpythonʵÏÖcrc32Çó×Ö·û´®Ð£ÑéÂë


תÌû£º
http://blog.csdn.net/wyingquan/archive/2008/12/20/3561094.aspx
ÓÃpython×Ô´øµÄbinasciiÄ£¿é¼ÆËã×Ö·û´®µÄУÑéÂ룬³öÀ´µÄÊǸºÖµ£¬ÓëÓÃcдµÄ³ÌÐòµÃ³öµÄУÑéÂë²»Ò»Ñù£¬ËùÒÔ¾ÍÑо¿ÁËһϡ£·¢ÏÖ±ðÈËÓõÄpython3.0°æ±¾binasciiÄ£¿é¼ÆËã³öµÄcrc32УÑéÂëÊÇÎÒÏëÒªµÄ£¬Ã»°ì·¨Ö»ºÃ×Ô¼ºÓÃpythonʵÏÖÒ»ÏÂcrc32µÄËã·¨ÁË¡£·¢ ......

»°ËµPython£¨Ò»£©

С°×ºÍС²ËÊÇ´óѧͬѧ£¬Õâ²»¿ìÒª±ÏÒµÁË£¬Á©ÈËÒ»ºÏ¼Æ£¬ÕÒ¸öÅàѵ°àѧµã¶«Î÷£¬Îä×°Ò»ÏÂÍ·ÄÔ£¬Ë³±ã½â¾ö¾ÍÒµÎÊÌâ¡£
“ÄãÃÇÒª±¨Äĸö°à°¡£¿”½Ó´ýËûÃǵÄÄêÇáС½ãÈÈÐĵØÎʵÀ¡£
“ÄãÃÇÕâÀïÄĸö°à×îºÃ£¿”С°×²»¼Ù˼Ë÷µØ˵£¬“µ±È»ÊDZ¨×îºÃµÄ°àÀ²¡£”
“ÎÒÃǹ«Ë¾µÄÅàѵÏîÄ¿¶¼ºÜºÃ”С½ãЦ ......

PythonͨѶ²¾

ÕâÁ½ÌìÔÚѧϰpythonÓïÑÔ£¬Ò²Ñ§×ÅдÁ˸öͨѶ²¾£¬Á·Ï°ÈëÃÅÏ£¡
¹¦ÄÜ°üÀ¨ÒÔÏ£º
1¡¢Ôö¼ÓÒ»Ìõ¼Ç¼
2¡¢É¾³ýÒ»Ìõ¼Ç¼
3¡¢ÐÞ¸ÄÒ»Ìõ¼Ç¼
4¡¢²éѯһÌõ¼Ç¼
5¡¢ÏÔʾÕû¸öͨѶ²¾
6¡¢°ïÖúÌáʾ
7¡¢°æ±¾ÏÔʾ
8¡¢Í˳öµÈ
Ê×ÏȽ¨Á¢Ò»¸öPersonÀ࣬¼´Person.pyÎļþ£¬ÓÃÀ´±£´æÁªÏµÈ˼Ǽ£º
class Person:
def __init__(self, nam ......

Python¸ÅÊö

    Python ÊÇÃâ·ÑµÄ½âÊÍÐÔÓïÑÔ£¬¾ßÓÐÃæÏò¶ÔÏóµÄÌØÐÔ¡£¿ÉÒÔÔËÐÐÔÚ¶àÖÖ²Ù×÷ϵͳ֮ÉÏ£¬Python¾ßÓÐÇåÎúµÄ½á¹¹£¬¼ò½àµÄÓï·¨ÒÔ¼°Ç¿´óµÄ¹¦ÄÜ¡£Python¿ÉÒÔÍê³É´ÓÎı¾´¦Àíµ½ÍøÂçͨÐŵȸ÷ÖÖ¹¤×÷£¬python×ÔÉíÒѾ­ÌṩÁË´óÁ¿µÄÄ£¿éÀ´ÊµÏÖ¸÷ÖÖ¹¦ÄÜ£¬³ý´ËÒÔÍ⻹¿ÉÒÔʹÓÃC/C++À´À©Õ¹Python£¬ÉõÖÁ»¹¿ÉÒÔ½«PythonǶÈëµ½ÆäËûÓ ......

Python ÖеÄ×Ö·û±àÂë

1¡¢strÀàÐÍ¿ÉÒÔÀí½âΪһ¸ö¶þ½øÖÆblock£¬»òmultibyte
2¡¢multibyte_str.decode("<multibyte_encode_method>")  -> unicode
3¡¢unicode_str.encode("<multibyte_encode_method>")  -> multibyte_str(binary block)
4¡¢unicode_str µÄ²Ù×÷²ÎÊýҲӦΪunicode£¬È磺unicode_str.find("Ñù±¾".deco ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ