Python论坛  - 讨论区

标题:[python-chinese] 请教python的 TCPServer的用法

2007年07月02日 星期一 22:14

Brightman mr.brightman在gmail.com
星期一 七月 2 22:14:04 HKT 2007

ÎÒµÄÓ÷¨ÈçÏ£¬µ«ÔÚʵ¼ÊʹÓÃÖÐÊÇÓÐÎÊÌâµÄ¡£ÔËÐÐʱ¼ä³¤ÁË£¬·þÎñÆ÷È«²¿±»
SYN_RECV×èÈûס¡£

def tbsvr(port):
class StreamHandler(StreamRequestHandler):
def handle(self):
fmt = "II64sII64sHHII252s" #recevie package struct
ssize = calcsize(fmt)
while 1:
try:
data = self.rfile.read(ssize)
self.wfile.write("y")
except Exception,e:
logging.warning("err in network: %s",str(e))
return #ÔÚCÖÐÖ÷¶¯¶Ï¿ªÁ¬½ÓÓ¦¸Ãµ÷ÓÃclose(client)²»ÖªµÀPythonÓ¦¸ÃÔõô´¦Àí£¿
work_func(data)
svr=TCPServer(('',port),StreamHandler)
svr.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
svr.socket.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1)
svr.serve_forever()

лл:)
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070702/469b0eff/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年07月02日 星期一 23:13

沈崴 wileishn在gmail.com
星期一 七月 2 23:13:51 HKT 2007

def tbsvr(port):
    class StreamHandler(StreamRequestHandler):
       def setup(self):
            self.connection = self.request
            self.rfile = self.connection.makefile('rb', self.rbufsize)
            self.wfile = self.connection.makefile('wb', self.wbufsize)
            self.connection.settimeout(1) # (-_-!)

       def handle(self):
            fmt = "II64sII64sHHII252s"  #recevie package struct
            ssize = calcsize(fmt)
            while 1:
                try:
                    data = self.rfile.read(ssize)
                    self.wfile.write("y")
                except Exception,e:
                    logging.warning("err in network: %s",str(e))
                    return # (^_^)
             work_func(data)
    svr=TCPServer(('',port),StreamHandler)
    svr.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
    svr.socket.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1)
    svr.serve_forever()

在 07-7-2,Brightman<mr.brightman在gmail.com> 写道:
>
>  我的用法如下,但在实际使用中是有问题的。运行时间长了,服务器全部被SYN_RECV阻塞住。
>
>  def tbsvr(port):
>      class StreamHandler(StreamRequestHandler):
>         def handle(self):
>              fmt = "II64sII64sHHII252s"  #recevie package struct
>              ssize = calcsize(fmt)
>              while 1:
>                  try:
>                      data = self.rfile.read(ssize)
>                      self.wfile.write("y")
>                  except Exception,e:
>                      logging.warning("err in network: %s",str(e))
>                      return
> #在C中主动断开连接应该调用close(client)不知道Python应该怎么处理?
>               work_func(data)
>      svr=TCPServer(('',port),StreamHandler)
>      svr.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
>      svr.socket.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1)
>      svr.serve_forever()
>
>  谢谢:)
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>

---
沈崴 (努力學習 Python 中 ...)
http://blog.163.com/eishn

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年07月03日 星期二 09:21

Neo Chen openunix在163.com
星期二 七月 3 09:21:29 HKT 2007

ÓÃͬ²½.¼´¿É..
ÄãÖ±½Óдsocket PythonÐÔÄܺܲîµÄ..Äã×îºÃÓÿò¼Ü.TwxxxʲôµÄ..
  ----- Original Message ----- 
  From: Brightman 
  To: python-chinese在lists.python.cn ; python-cn在googlegroups.com 
  Sent: Monday, July 02, 2007 10:14 PM
  Subject: [python-chinese] Çë½ÌpythonµÄ TCPServerµÄÓ÷¨


  ÎÒµÄÓ÷¨ÈçÏ£¬µ«ÔÚʵ¼ÊʹÓÃÖÐÊÇÓÐÎÊÌâµÄ¡£ÔËÐÐʱ¼ä³¤ÁË£¬·þÎñÆ÷È«²¿±»SYN_RECV×èÈûס¡£

  def tbsvr(port):
      class StreamHandler(StreamRequestHandler):
         def handle(self):
              fmt = "II64sII64sHHII252s"  #recevie package struct
              ssize = calcsize(fmt)
              while 1:
                  try:
                      data = self.rfile.read(ssize)
                      self.wfile.write("y")
                  except Exception,e:
                      logging.warning("err in network: %s",str(e))
                      return        #ÔÚCÖÐÖ÷¶¯¶Ï¿ªÁ¬½ÓÓ¦¸Ãµ÷ÓÃclose(client)²»ÖªµÀPythonÓ¦¸ÃÔõô´¦Àí£¿
               work_func(data)
      svr=TCPServer(('',port),StreamHandler)
      svr.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
      svr.socket.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1)
      svr.serve_forever()

  лл:)



------------------------------------------------------------------------------


  _______________________________________________
  python-chinese
  Post: send python-chinese在lists.python.cn
  Subscribe: send subscribe to python-chinese-request在lists.python.cn
  Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
  Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070703/7669cafd/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年07月03日 星期二 10:32

Brightman mr.brightman在gmail.com
星期二 七月 3 10:32:24 HKT 2007

沈崴 写道:
> def tbsvr(port):
>     class StreamHandler(StreamRequestHandler):
>        def setup(self):
>             self.connection = self.request
>             self.rfile = self.connection.makefile('rb', self.rbufsize)
>             self.wfile = self.connection.makefile('wb', self.wbufsize)
>             self.connection.settimeout(1) # (-_-!)这个是什么超时?
> 不设置,默认超时是多长时间?还有读超时,写超时都在何处设置?谢谢
>        def handle(self):
>             fmt = "II64sII64sHHII252s"  #recevie package struct
>             ssize = calcsize(fmt)
>             while 1:
>                 try:
>                     data = self.rfile.read(ssize)
>                     self.wfile.write("y")
>                 except Exception,e:
>                     logging.warning("err in network: %s",str(e))
>                     return # (^_^)
>              work_func(data)
>     svr=TCPServer(('',port),StreamHandler)
>     svr.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
>     svr.socket.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1)
>     svr.serve_forever()
>
> 在 07-7-2,Brightman<mr.brightman在gmail.com> 写道:
>   
>>  我的用法如下,但在实际使用中是有问题的。运行时间长了,服务器全部被SYN_RECV阻塞住。
>>
>>  def tbsvr(port):
>>      class StreamHandler(StreamRequestHandler):
>>         def handle(self):
>>              fmt = "II64sII64sHHII252s"  #recevie package struct
>>              ssize = calcsize(fmt)
>>              while 1:
>>                  try:
>>                      data = self.rfile.read(ssize)
>>                      self.wfile.write("y")
>>                  except Exception,e:
>>                      logging.warning("err in network: %s",str(e))
>>                      return
>> #在C中主动断开连接应该调用close(client)不知道Python应该怎么处理?
>>               work_func(data)
>>      svr=TCPServer(('',port),StreamHandler)
>>      svr.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
>>      svr.socket.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1)
>>      svr.serve_forever()
>>
>>  谢谢:)
>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese在lists.python.cn
>> Subscribe: send subscribe to
>> python-chinese-request在lists.python.cn
>> Unsubscribe: send unsubscribe to
>> python-chinese-request在lists.python.cn
>> Detail Info:
>> http://python.cn/mailman/listinfo/python-chinese
>>
>>     
>
> ---
> 沈崴 (努力學習 Python 中 ...)
> http://blog.163.com/eishn
>
> --~--~---------~--~----~------------~-------~--~----~
> '''邮件来自Groups "python-cn"--China Py User Group
> 详情: http://groups-beta.google.com/group/python-cn
> 发言: python-cn在googlegroups.com
> 退订: python-cn-unsubscribe在googlegroups.com
> 维基: http://wiki.woodpecker.org.cn/moin/CPUG
> 同类列表: http://python.cn/mailman/listinfo/python-chinese
> 社区事务: http://groups.google.com/group/CPUG
> 北京事务: http://groups.google.com/group/bpug
> 东南事务: http://groups.google.com/group/cpug-eastchina
> '''
> -~----------~----~----~----~------~----~------~--~---
>
>   

-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070703/e1f17947/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年07月03日 星期二 11:30

Brightman mr.brightman在gmail.com
星期二 七月 3 11:30:21 HKT 2007

Neo Chen 写道:
> 用同步.即可..
你说的同步是指什么?代码中如何体现,谢谢
> 你直接写socket Python性能很差的..你最好用框架.Twxxx什么的..
>
>     ----- Original Message -----
>     *From:* Brightman mr.brightman在gmail.com>
>     *To:* python-chinese在lists.python.cn
>     python-chinese在lists.python.cn> ;
>     python-cn在googlegroups.com python-cn在googlegroups.com>
>     *Sent:* Monday, July 02, 2007 10:14 PM
>     *Subject:* [python-chinese] 请教python的 TCPServer的用法
>
>     我的用法如下,但在实际使用中是有问题的。运行时间长了,服务器全部被
>     SYN_RECV阻塞住。
>
>     def tbsvr(port):
>     class StreamHandler(StreamRequestHandler):
>     def handle(self):
>     fmt = "II64sII64sHHII252s" #recevie package struct
>     ssize = calcsize(fmt)
>     while 1:
>     try:
>     data = self.rfile.read(ssize)
>     self.wfile.write("y")
>     except Exception,e:
>     logging.warning("err in network: %s",str(e))
>     return #在C中主动断开连接应该调用close(client)不知道Python应该怎么
>     处理?
>     work_func(data)
>     svr=TCPServer(('',port),StreamHandler)
>     svr.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
>     svr.socket.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1)
>     svr.serve_forever()
>
>     谢谢:)
>
>     ------------------------------------------------------------------------
>     _______________________________________________
>     python-chinese
>     Post: send python-chinese在lists.python.cn
>     Subscribe: send subscribe to python-chinese-request在lists.python.cn
>     Unsubscribe: send unsubscribe to
>     python-chinese-request在lists.python.cn
>     Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年07月03日 星期二 11:37

Neo Chen openunix在163.com
星期二 七月 3 11:37:09 HKT 2007

asyncore , asynchat 

----- Original Message ----- 
From: "Brightman" <mr.brightman在gmail.com>
To: <python-chinese在lists.python.cn>
Sent: Tuesday, July 03, 2007 11:30 AM
Subject: Re: [python-chinese] 请教python的 TCPServer的用法


> Neo Chen 写道:
>> 用同步.即可..
> 你说的同步是指什么?代码中如何体现,谢谢
>> 你直接写socket Python性能很差的..你最好用框架.Twxxx什么的..
>>
>>     ----- Original Message -----
>>     *From:* Brightman mr.brightman在gmail.com>
>>     *To:* python-chinese在lists.python.cn
>>     python-chinese在lists.python.cn> ;
>>     python-cn在googlegroups.com python-cn在googlegroups.com>
>>     *Sent:* Monday, July 02, 2007 10:14 PM
>>     *Subject:* [python-chinese] 请教python的 TCPServer的用法
>>
>>     我的用法如下,但在实际使用中是有问题的。运行时间长了,服务器全部被
>>     SYN_RECV阻塞住。
>>
>>     def tbsvr(port):
>>     class StreamHandler(StreamRequestHandler):
>>     def handle(self):
>>     fmt = "II64sII64sHHII252s" #recevie package struct
>>     ssize = calcsize(fmt)
>>     while 1:
>>     try:
>>     data = self.rfile.read(ssize)
>>     self.wfile.write("y")
>>     except Exception,e:
>>     logging.warning("err in network: %s",str(e))
>>     return #在C中主动断开连接应该调用close(client)不知道Python应该怎么
>>     处理?
>>     work_func(data)
>>     svr=TCPServer(('',port),StreamHandler)
>>     svr.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
>>     svr.socket.setsockopt(socket.IPPROTO_TCP,socket.TCP_NODELAY,1)
>>     svr.serve_forever()
>>
>>     谢谢:)
>>
>>     ------------------------------------------------------------------------
>>     _______________________________________________
>>     python-chinese
>>     Post: send python-chinese在lists.python.cn
>>     Subscribe: send subscribe to python-chinese-request在lists.python.cn
>>     Unsubscribe: send unsubscribe to
>>     python-chinese-request在lists.python.cn
>>     Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese在lists.python.cn
>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
> 
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年07月06日 星期五 10:56

doudou doudou array.doudou在gmail.com
星期五 七月 6 10:56:21 HKT 2007

ÓÃTwisted°É
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070706/95c54b77/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年07月06日 星期五 12:01

沈崴 wileishn在gmail.com
星期五 七月 6 12:01:40 HKT 2007

Twisted Medusa SocketServer.py socket.py socketlib stacklesssocket.py
asynchat.py asyncore.py AsyncHTTPServer.py asyncserver.py django
TurboGears pylones cherrypy web.py mod_python Jon'sXXX psa zope PEP333
webware SkunkWeb spyce albatross

用过的人都说好, 欢迎选购 :D

在 07-7-6,doudou doudou<array.doudou在gmail.com> 写道:
> 用Twisted吧
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>

---
沈崴 (努力学习 Python 中 ...)
http://blog.163.com/eishn
http://code.google.com/p/njf
http://code.google.com/p/eurasia

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年07月06日 星期五 12:25

haur hekun06在gmail.com
星期五 七月 6 12:25:40 HKT 2007

ËýºÃ,ÄãÒ²ºÃ

2007/7/6, ÉòáË <wileishn在gmail.com>:
>
> Twisted Medusa SocketServer.py socket.py socketlib stacklesssocket.py
> asynchat.py asyncore.py AsyncHTTPServer.py asyncserver.py django
> TurboGears pylones cherrypy web.py mod_python Jon'sXXX psa zope PEP333
> webware SkunkWeb spyce albatross
>
> ÓùýµÄÈ˶¼ËµºÃ, »¶Ó­Ñ¡¹º :D
>
> ÔÚ 07-7-6£¬doudou doudou<array.doudou在gmail.com> дµÀ£º
> > ÓÃTwisted°É
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to
> > python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> > Detail Info:
> > http://python.cn/mailman/listinfo/python-chinese
> >
>
> ---
> ÉòáË (ŬÁ¦Ñ§Ï° Python ÖÐ ...)
> http://blog.163.com/eishn
> http://code.google.com/p/njf
> http://code.google.com/p/eurasia
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070706/c47b00f1/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号