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

python socket 模块小型服务器程序有问题

  •  
  •   ljcarsenal · Mar 2, 2014 · 3626 views
    This topic created in 4482 days ago, the information mentioned may be changed or developed.
    《python web开发学习实录》里 有个小型服务器程序 我照着敲的 有错误 上网查也没有查到

    import socket
    s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
    host=socket.gethostname()
    print host
    port=1234
    s.bind((host,port))
    s.listen(5)
    while True:
    c,addr=s.accept()
    print 'lianjielaizi',addr
    c.send('success')
    c.close()


    Traceback (most recent call last):
    File "/home/ljc/桌面/so", line 7, in <module>
    s.listen(5)
    File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
    socket.error: [Errno 95] Operation not supported

    求解答
    3 replies    1970-01-01 08:00:00 +08:00
    ljcarsenal
        1
    ljcarsenal  
    OP
       Mar 2, 2014
    缩进都没有了。。。。。while后有缩进的
    SErHo
        2
    SErHo  
       Mar 2, 2014   ❤️ 1
    socket.SOCK_DGRAM 是 UDP,这里你需要 TCP,改成 socket.SOCK_STREAM
    ljcarsenal
        3
    ljcarsenal  
    OP
       Mar 2, 2014
    @SErHo 确实是这样的,我看错了 谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   959 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 21:57 · PVG 05:57 · LAX 14:57 · JFK 17:57
    ♥ Do have faith in what you're doing.