FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-websocket-server/server.py at patch-1 · YYYGH/python-websocket-server · GitHub
YYYGH
python-websocket-server
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-websocket-server
/
server.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (19 loc) · 778 Bytes
Breadcrumbs
python-websocket-server
/
server.py
Copy path
File metadata and controls
26 lines (19 loc) · 778 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from
websocket_server
import
WebsocketServer
# Called for every client connecting (after handshake)
def
new_client
(
client
,
server
):
print
(
"New client connected and was given id %d"
%
client
[
'id'
])
server
.
send_message_to_all
(
"Hey all, a new client has joined us"
)
# Called for every client disconnecting
def
client_left
(
client
,
server
):
print
(
"Client(%d) disconnected"
%
client
[
'id'
])
# Called when a client sends a message
def
message_received
(
client
,
server
,
message
):
if
len
(
message
)
>
200
:
message
=
message
[:
200
]
+
'..'
print
(
"Client(%d) said: %s"
%
(
client
[
'id'
],
message
))
PORT
=
9001
server
=
WebsocketServer
(
PORT
)
server
.
set_fn_new_client
(
new_client
)
server
.
set_fn_client_left
(
client_left
)
server
.
set_fn_message_received
(
message_received
)
server
.
run_forever
()
Back
|
FazBrowse Home
|
New Git URL