Skip to content

WebSocketWithGevent

Benoit de Chezelles edited this page Jul 12, 2018 · 3 revisions

WebSocket client with gevent

gevent(http://www.gevent.org/) is a coroutine-based Python networking library. You can use websocket-client with gevent. It is easy to use. At first, apply monkey patch. And that's all.

example:

import gevent
from gevent import monkey
monkey.patch_all()

from websocket import create_connection
ws = create_connection("ws://echo.websocket.org")
print "Sending 'Hello, World'..."
ws.send("Hello, World")
print "Sent"
print "Receiving..."
result =  ws.recv()
print "Received '%s'" % result
ws.close()
Clone this wiki locally