5 websocket-client module is WebSocket client for python. This provide the low level APIs for WebSocket. All APIs are the synchronous functions.
7 websocket-client supports only hybi-13.
17 This module is tested on only Python 2.7.
19 Type "python setup.py install" or "pip install websocket-client" to install.
21 This module does not depend on any other module.
24 ===========================
26 py3( https://github.com/liris/websocket-client/tree/py3 ) branch is for python 3.3. Every test case is passed.
27 If you are using python3, please check it.
32 Low Level API example::
34 from websocket import create_connection
35 ws = create_connection("ws://echo.websocket.org/")
36 print "Sending 'Hello, World'..."
37 ws.send("Hello, World")
41 print "Received '%s'" % result
44 If you want to customize socket options, set sockopt.
48 from websocket import create_connection
49 ws = create_connection("ws://echo.websocket.org/".
50 sockopt=((socket.IPPROTO_TCP, socket.TCP_NODELAY),) )
53 JavaScript websocket-like API example::
59 def on_message(ws, message):
62 def on_error(ws, error):
66 print "### closed ###"
72 ws.send("Hello %d" % i)
75 print "thread terminating..."
76 thread.start_new_thread(run, ())
79 if __name__ == "__main__":
80 websocket.enableTrace(True)
81 ws = websocket.WebSocketApp("ws://echo.websocket.org/",
82 on_message = on_message,
93 wsdump.py is simple WebSocket test(debug) tool.
95 sample for echo.websocket.org::
97 $ wsdump.py ws://echo.websocket.org/
108 wsdump.py [-h] [-v [VERBOSE]] ws_url
110 WebSocket Simple Dump Tool
112 positional arguments:
113 ws_url websocket url. ex. ws://echo.websocket.org/
116 -h, --help show this help message and exit
118 -v VERBOSE, --verbose VERBOSE set verbose mode. If set to 1, show opcode. If set to 2, enable to trace websocket module
122 $ wsdump.py ws://echo.websocket.org/
123 $ wsdump.py ws://echo.websocket.org/ -v
124 $ wsdump.py ws://echo.websocket.org/ -vv
131 - support keep alive for WebSocketApp(ISSUE#34)
132 - fix some SSL bugs(ISSUE#35, #36)
133 - fix "Timing out leaves websocket library in bad state"(ISSUE#37)
134 - fix "WebSocketApp.run_with_no_err() silently eats all exceptions"(ISSUE#38)
135 - WebSocketTimeoutException will be raised for ws/wss timeout(ISSUE#40)
136 - improve wsdump message(ISSUE#42)
137 - support fragmentation message(ISSUE#43)
142 - Only log non-normal close status(ISSUE#31)
143 - Fix default Origin isn't URI(ISSUE#32)
144 - fileno support(ISSUE#33)
148 - allow to set HTTP Header to WebSocketApp(ISSUE#27)
149 - fix typo in pydoc(ISSUE#28)
150 - Passing a socketopt flag to the websocket constructor(ISSUE#29)
151 - websocket.send fails with long data(ISSUE#30)
156 - allow to set opcode in WebSocketApp.send(ISSUE#25)
157 - allow to modify Origin(ISSUE#26)
162 - some performance improvement
166 - fixed problem to read long data.(ISSUE#12)
167 - fix buffer size boundary violation
171 - Patches: UUID4, self.keep_running, mask_key (ISSUE#11)
176 - fix Echo App Demo Throw Error: 'NoneType' object has no attribute 'opcode (ISSUE#10)
180 - delete invalid print statement.
184 - support hybi-13 protocol.
188 - fix incorrect custom header order(ISSUE#1)