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
YangJian1994
V2EX  ›  Python

我想问一下各位大佬,我最近用 Python 写了一个 socketserver(python3 版本),继承 socketserver.BaseRequestHandler,在 handle 函数里面写了一个 while 循环接受数据。

  •  1
     
  •   YangJian1994 · 2018-01-17 19:41:09 +08:00 · 3422 次点击
    这是一个创建于 2261 天前的主题,其中的信息可能已经有所发展或是发生改变。

    def handle(self): connection = self.request while True: bytesData = connection.recv(1024) if not bytesData: break
    strData = byte2Hex(bytesData) print(strData)

    于是我用 TCP 工具去连接,并发送数据,服务端接受数据没问题,但是只要我断开 TCP 连接,服务端就会出现这个错误。ConnectionResetError:(Errno 104)Connection reset by peer,各位大佬帮忙看看。

    3 条回复    2018-01-18 16:45:41 +08:00
    CEBBCAT
        1
    CEBBCAT  
       2018-01-18 00:11:00 +08:00 via Android
    断开是 Ctrl + C 还是 name.close() ?
    hsuan
        2
    hsuan  
       2018-01-18 10:57:53 +08:00
    你断开连接报 reset by peer 不是很正常吗?
    white1222
        3
    white1222  
       2018-01-18 16:45:41 +08:00
    看着费眼
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3896 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:30 · PVG 18:30 · LAX 03:30 · JFK 06:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.