| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
python-websocket is a Python/asyncore WebSocket client library.
While the primary intention of the WebSocket protocol is to enable "TCP-like" full-duplex communication from within a web apps, it also provides a number of benefits (over plain TCP) for desktop apps:
def my_msg_handler(msg):
print 'Got "%s"!' % msg
socket = WebSocket('ws://example.com/demo', onmessage=my_msg_handler)
socket.onopen = lambda: socket.send('Hello world!')
try:
asyncore.loop()
except KeyboardInterrupt:
socket.close()
Returns a WebSocket connected to a remote host at the given url. In order to allow communication over this socket, asyncore.loop() must be called by the client.
The optional protocol parameter can be used to specify the sub-protocol to be used. By providing a cookie_jar (cookielib), appropriate cookies will be sent to the server.
The remaining parameters are callback functions that will be invoked in the following manner:
onopen: invoked when a connection to the remote host has been
successfully established
onmessage: invoked when a message is received (passing the
received data as an argument to the callback
function)
onerror: invoked when a communication error occured (passing
an Exception instance as an argument to the callback
function). If onerror is not provided, the default
asyncore behavior is used (raising the exception)
onclose: invoked when the connection has closed _normally_ (by
request from either client or server)
Sends data through the socket.
Closes the socket.
| Back | FazBrowse Home | New Git URL |