|
26 | 26 | <meta property="og:url" content="http://localhost:1313/notes/python/web/">
|
27 | 27 | <meta property="og:site_name" content="Stefano Giannini">
|
28 | 28 | <meta property="og:title" content="WebSocket">
|
29 |
| - <meta property="og:description" content="Connect to a Websocket A sample python program is show here. import websocket def on_message(ws, message): print(message) def on_error(ws, error): print(f"Encountered error: {error}") def on_close(ws, close_status_code, close_msg): print("Connection closed") def on_open(ws): print("Connection opened") ws.send("Hello, Worldy!") if __name__ == "__main__": ws = websocket.WebSocketApp("ws://localhost:xxxx", # insert here you websocket addres on_message=on_message, on_error=on_error, on_close=on_close) ws.on_open = on_open ws.run_forever() Run the program as below: $ python websocket_example.py -->"> |
| 29 | + <meta property="og:description" content="Connect to a Websocket A sample python program is shown here. import websocket def on_message(ws, message): print(message) def on_error(ws, error): print(f"Encountered error: {error}") def on_close(ws, close_status_code, close_msg): print("Connection closed") def on_open(ws): print("Connection opened") ws.send("Hello, Worldy!") if __name__ == "__main__": ws = websocket.WebSocketApp("ws://localhost:xxxx", # insert here you websocket addres on_message=on_message, on_error=on_error, on_close=on_close) ws.on_open = on_open ws.run_forever() Run the program as below: $ python websocket_example.py -->"> |
30 | 30 | <meta property="og:locale" content="en">
|
31 | 31 | <meta property="og:type" content="article">
|
32 | 32 | <meta property="article:section" content="notes">
|
33 | 33 |
|
34 | 34 |
|
35 | 35 | <meta name="twitter:card" content="summary">
|
36 | 36 | <meta name="twitter:title" content="WebSocket">
|
37 |
| - <meta name="twitter:description" content="Connect to a Websocket A sample python program is show here. import websocket def on_message(ws, message): print(message) def on_error(ws, error): print(f"Encountered error: {error}") def on_close(ws, close_status_code, close_msg): print("Connection closed") def on_open(ws): print("Connection opened") ws.send("Hello, Worldy!") if __name__ == "__main__": ws = websocket.WebSocketApp("ws://localhost:xxxx", # insert here you websocket addres on_message=on_message, on_error=on_error, on_close=on_close) ws.on_open = on_open ws.run_forever() Run the program as below: $ python websocket_example.py -->"> |
| 37 | + <meta name="twitter:description" content="Connect to a Websocket A sample python program is shown here. import websocket def on_message(ws, message): print(message) def on_error(ws, error): print(f"Encountered error: {error}") def on_close(ws, close_status_code, close_msg): print("Connection closed") def on_open(ws): print("Connection opened") ws.send("Hello, Worldy!") if __name__ == "__main__": ws = websocket.WebSocketApp("ws://localhost:xxxx", # insert here you websocket addres on_message=on_message, on_error=on_error, on_close=on_close) ws.on_open = on_open ws.run_forever() Run the program as below: $ python websocket_example.py -->"> |
38 | 38 |
|
39 | 39 |
|
40 | 40 |
|
|
321 | 321 | <h5 class="note-title"><span>Connect to a Websocket</span></h5>
|
322 | 322 |
|
323 | 323 | <div class="card">
|
324 |
| - <div class="card-body"><p>A sample <strong>python</strong> program is show here.</p> |
| 324 | + <div class="card-body"><p>A sample <strong>python</strong> program is shown here.</p> |
325 | 325 | <div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#f92672">import</span> websocket
|
326 | 326 | </span></span><span style="display:flex;"><span>
|
327 | 327 | </span></span><span style="display:flex;"><span>
|
|
0 commit comments