python实现的WebSocket客户

发布时间:2019-09-25 08:19:08编辑:auto阅读(2173)

    安装

    sudo pip install websocket-client

    示例客户端代码:

    #!/usr/bin/python
    
    from websocket import create_connection
    ws = create_connection("ws://localhost:8080/websocket")
    print "Sending 'Hello, World'..."
    ws.send("Hello, World")
    print "Sent"
    print "Reeiving..."
    result =  ws.recv()
    print "Received '%s'" % result
    ws.close()

关键字