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

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

  •  
  •   ljcarsenal · 2014-03-02 20:38:35 +08:00 · 3107 次点击
    这是一个创建于 3714 天前的主题,其中的信息可能已经有所发展或是发生改变。
    《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 条回复    1970-01-01 08:00:00 +08:00
    ljcarsenal
        1
    ljcarsenal  
    OP
       2014-03-02 20:39:58 +08:00
    缩进都没有了。。。。。while后有缩进的
    SErHo
        2
    SErHo  
       2014-03-02 20:44:39 +08:00   ❤️ 1
    socket.SOCK_DGRAM 是 UDP,这里你需要 TCP,改成 socket.SOCK_STREAM
    ljcarsenal
        3
    ljcarsenal  
    OP
       2014-03-02 21:12:36 +08:00
    @SErHo 确实是这样的,我看错了 谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2151 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:44 · PVG 18:44 · LAX 03:44 · JFK 06:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.