You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
3.`pip install websocket-server` (might not be up-to-date)
31
37
32
38
For coding details have a look at the [*server.py*](https://github.com/Pithikos/python-websocket-server/blob/master/server.py) example and the [API](https://github.com/Pithikos/python-websocket-server#api).
33
39
@@ -39,18 +45,23 @@ The API is simply methods and properties of the `WebsocketServer` class.
39
45
40
46
## WebsocketServer
41
47
42
-
The WebsocketServer takes two arguments: a `port` and a `hostname`.
43
-
By default the localhost `127.0.0.1` is used. However if you want to be able and connect
44
-
to the server from the network you need to pass `0.0.0.0` as hostname e.g. `WebsocketServer(13254, host='0.0.0.0')`.
48
+
The WebsocketServer can be initialized with the below parameters.
45
49
46
-
###Properties
50
+
*`port`* - The port clients will need to connect to.
51
+
52
+
*`host`* - By default the `127.0.0.1` is used which allows connections only from the current machine. If you wish to allow all network machines to connect, you need to pass `0.0.0.0` as hostname.
53
+
54
+
*`loglevel`* - logging level to print. By default WARNING is used. You can use `logging.DEBUG` or `logging.INFO` for more verbose output.
@@ -70,23 +81,23 @@ to the server from the network you need to pass `0.0.0.0` as hostname e.g. `Webs
70
81
|`set_fn_message_received()`| Called when a `client` sends a `message`| client, server, message |
71
82
72
83
73
-
The client passed to the callback is the client that left, sent the message, etc. The server might not have any use to use. However it is
74
-
passed in case you want to send messages to clients.
84
+
The client passed to the callback is the client that left, sent the message, etc. The server might not have any use to use. However it is passed in case you want to send messages to clients.
75
85
76
86
77
87
Example:
78
88
````
89
+
import logging
79
90
from websocket_server import WebsocketServer
80
91
81
92
def new_client(client, server):
82
93
server.send_message_to_all("Hey all, a new client has joined us")
83
94
84
-
server = WebsocketServer(13254, host='127.0.0.1')
95
+
server = WebsocketServer(13254, host='127.0.0.1', loglevel=logging.INFO)
85
96
server.set_fn_new_client(new_client)
86
97
server.run_forever()
87
98
````
88
99
89
-
##Client
100
+
##Client
90
101
91
102
Client is just a dictionary passed along methods.
92
103
@@ -97,4 +108,3 @@ Client is just a dictionary passed along methods.
0 commit comments