V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
siw
V2EX  ›  Python

Python socketserver 菜鸟求助

  •  
  •   siw · 2013-07-07 21:11:34 +08:00 · 2936 次点击
    这是一个创建于 3942 天前的主题,其中的信息可能已经有所发展或是发生改变。
    import socketserver

    class MyTCPHandler(socketserver.BaseRequestHandler):
    def handle(self):
    self.data = self.request.recv(1024).strip()

    print("%s wrote:" % self.client_address[0])
    print(self.data)

    self.request.send("YES")

    if __name__ == "__main__":
    listenon = "127.0.0.1"
    listenport = 7000
    server = socketserver.TCPServer((listenon, listenport), MyTCPHandler)
    server.serve_forever()

    以上服务端代码, 为什么第一次connect的时候 发送xxx, 输出 YES, 接下来在客户端发送其他的xxx却没有输出"YES" 呢?
    1 条回复    1970-01-01 08:00:00 +08:00
    siw
        1
    siw  
    OP
       2013-07-07 21:27:10 +08:00
    是不是从handle后, 就socket close 了?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5395 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 07:22 · PVG 15:22 · LAX 00:22 · JFK 03:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.