V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Jul 7, 2013 · 3874 views
    This topic created in 4689 days ago, the information mentioned may be changed or developed.
    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 replies    1970-01-01 08:00:00 +08:00
    siw
        1
    siw  
    OP
       Jul 7, 2013
    是不是从handle后, 就socket close 了?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2787 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:41 · PVG 09:41 · LAX 18:41 · JFK 21:41
    ♥ Do have faith in what you're doing.