推荐学习书目
› 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
617450941
V2EX  ›  Python

socket 断线重连怎么实现

  •  
  •   617450941 · Dec 12, 2015 · 8238 views
    This topic created in 3944 days ago, the information mentioned may be changed or developed.
    客户端 到服务端期间网络中断 socket 怎么实现断线重连 有没示例代码供参考
    10 replies  •  2015-12-14 17:47:41 +08:00
    est
        1
    est  
       Dec 12, 2015
    会写 socket 的做这个都不难吧。。。
    617450941
        2
    617450941  
    OP
       Dec 12, 2015 via Android
    @est 就是不会才问的
    zhonghua
        3
    zhonghua  
       Dec 12, 2015
    用 socket.io 吧
    youkeshen
        4
    youkeshen  
       Dec 12, 2015
    617450941
        5
    617450941  
    OP
       Dec 13, 2015 via Android
    @youkeshen 这是 js 的把
    fy
        6
    fy  
       Dec 13, 2015
    @617450941 简单呀 设定用户掉线,倒计时再次进行登录行为
    viaNull
        7
    viaNull  
       Dec 13, 2015
    UDP 的话没重连的概念
    TCP 的话需要一个心跳查看是否中断,如果中断,重新建立 TCP 连接就是了。
    Juggernaut
        8
    Juggernaut  
       Dec 13, 2015
    @viaNull 但是这都是协议栈级别的工作,上层 APP 不需要 care 这些
    617450941
        9
    617450941  
    OP
       Dec 14, 2015
    @fy
    @viaNull
    有没简单代码供参考
    fy
        10
    fy  
       Dec 14, 2015
    @617450941

    while (alive) {
    connect();
    recv(); // 阻塞住等消息,掉线后退出
    reset();
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5151 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 03:35 · PVG 11:35 · LAX 20:35 · JFK 23:35
    ♥ Do have faith in what you're doing.