Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wspy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
wspy
Commits
a95914e8
Commit
a95914e8
authored
Nov 07, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup
parent
0de6f644
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
8 deletions
+21
-8
server.py
server.py
+21
-8
No files found.
server.py
View file @
a95914e8
...
...
@@ -24,8 +24,8 @@ class Server(object):
def
run
(
self
):
while
True
:
try
:
client_socket
,
address
=
self
.
sock
.
accept
()
client
=
Client
(
self
,
client_socket
,
address
)
sock
,
address
=
self
.
sock
.
accept
()
client
=
Client
(
self
,
sock
,
address
)
client
.
handshake
()
self
.
clients
.
append
(
client
)
logging
.
info
(
'Registered client %s'
,
client
)
...
...
@@ -38,8 +38,12 @@ class Server(object):
except
Exception
as
e
:
logging
.
error
(
format_exc
(
e
))
def
remove_client
(
self
,
client
,
code
,
reason
):
self
.
clients
.
remove
(
client
)
self
.
onclose
(
client
,
code
,
reason
)
def
onopen
(
self
,
client
):
logging
.
debug
(
'Opened socket to
client
%s'
%
client
)
logging
.
debug
(
'Opened socket to %s'
%
client
)
def
onmessage
(
self
,
client
,
message
):
logging
.
debug
(
'Received %s from %s'
%
(
message
,
client
))
...
...
@@ -50,14 +54,23 @@ class Server(object):
def
onpong
(
self
,
client
,
payload
):
logging
.
debug
(
'Received pong "%s" from %s'
%
(
payload
,
client
))
def
onclose
(
self
,
client
):
logging
.
debug
(
'Closed socket to client %s'
%
client
)
def
onclose
(
self
,
client
,
code
,
reason
):
msg
=
'Closed socket to %s'
%
client
if
code
is
not
None
:
msg
+=
' [%d]'
%
code
if
len
(
reason
):
msg
+=
' "%s"'
%
reason
logging
.
debug
(
msg
)
class
Client
(
WebSocket
):
def
__init__
(
self
,
server
,
sock
,
address
):
super
(
Client
,
self
).
__init__
(
sock
,
address
)
super
(
Client
,
self
).
__init__
(
sock
)
self
.
server
=
server
self
.
address
=
address
def
onopen
(
self
):
self
.
server
.
onopen
(
self
)
...
...
@@ -71,8 +84,8 @@ class Client(WebSocket):
def
onpong
(
self
,
payload
):
self
.
server
.
onpong
(
self
,
payload
)
def
onclose
(
self
):
self
.
server
.
onclose
(
self
)
def
onclose
(
self
,
code
,
reason
):
self
.
server
.
remove_client
(
self
,
code
,
reason
)
def
__str__
(
self
):
return
'<Client at %s:%d>'
%
self
.
address
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment