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
5e9b432e
Commit
5e9b432e
authored
Aug 19, 2013
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed Server arguments 'hostname' and 'port' to an 'address' tuple for consistency
parent
5034eae4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
README.md
README.md
+1
-1
server.py
server.py
+9
-8
No files found.
README.md
View file @
5e9b432e
...
@@ -124,7 +124,7 @@ Basic usage
...
@@ -124,7 +124,7 @@ Basic usage
def onclose(self, client):
def onclose(self, client):
print 'Client %s disconnected' % client
print 'Client %s disconnected' % client
EchoServer(
8000
).run()
EchoServer(
('', 8000)
).run()
The server can be stopped by typing CTRL-C in the command line. The
The server can be stopped by typing CTRL-C in the command line. The
`KeyboardInterrupt`
raised when this happens is caught by the server.
`KeyboardInterrupt`
raised when this happens is caught by the server.
...
...
server.py
View file @
5e9b432e
...
@@ -29,15 +29,15 @@ class Server(object):
...
@@ -29,15 +29,15 @@ class Server(object):
>>> def onclose(self, client):
>>> def onclose(self, client):
>>> print 'Client %s disconnected' % client
>>> print 'Client %s disconnected' % client
>>> EchoServer(
8000
).run()
>>> EchoServer(
('', 8000)
).run()
"""
"""
def
__init__
(
self
,
port
,
hostname
=
''
,
loglevel
=
logging
.
INFO
,
protocols
=
[],
def
__init__
(
self
,
address
,
loglevel
=
logging
.
INFO
,
protocols
=
[],
secure
=
False
,
max_join_time
=
2.0
,
**
kwargs
):
secure
=
False
,
max_join_time
=
2.0
,
**
kwargs
):
"""
"""
Constructor for a simple websocket server.
Constructor for a simple web
socket server.
`
hostname` and `port` form the address to bind the web
socket to.
`
address` is a (hostname, port) tuple to bind the web
socket to.
`loglevel` values should be imported from the logging module.
`loglevel` values should be imported from the logging module.
logging.INFO only shows server start/stop messages, logging.DEBUG shows
logging.INFO only shows server start/stop messages, logging.DEBUG shows
...
@@ -48,8 +48,8 @@ class Server(object):
...
@@ -48,8 +48,8 @@ class Server(object):
`secure` is a flag indicating whether the server is SSL enabled. In
`secure` is a flag indicating whether the server is SSL enabled. In
this case, `keyfile` and `certfile` must be specified. Any additional
this case, `keyfile` and `certfile` must be specified. Any additional
keyword arguments are passed to
websocket.enable_ssl
(and thus to
keyword arguments are passed to
`websocket.enable_ssl`
(and thus to
ssl.wrap_socket
).
`ssl.wrap_socket`
).
`max_join_time` is the maximum time (in seconds) to wait for client
`max_join_time` is the maximum time (in seconds) to wait for client
responses after sending CLOSE frames, it defaults to 2 seconds.
responses after sending CLOSE frames, it defaults to 2 seconds.
...
@@ -59,6 +59,7 @@ class Server(object):
...
@@ -59,6 +59,7 @@ class Server(object):
datefmt
=
'%H:%M:%S'
)
datefmt
=
'%H:%M:%S'
)
scheme
=
'wss'
if
secure
else
'ws'
scheme
=
'wss'
if
secure
else
'ws'
hostname
,
port
=
address
logging
.
info
(
'Starting server at %s://%s:%d'
,
scheme
,
hostname
,
port
)
logging
.
info
(
'Starting server at %s://%s:%d'
,
scheme
,
hostname
,
port
)
self
.
sock
=
websocket
()
self
.
sock
=
websocket
()
...
@@ -67,7 +68,7 @@ class Server(object):
...
@@ -67,7 +68,7 @@ class Server(object):
if
secure
:
if
secure
:
self
.
sock
.
enable_ssl
(
server_side
=
True
,
**
kwargs
)
self
.
sock
.
enable_ssl
(
server_side
=
True
,
**
kwargs
)
self
.
sock
.
bind
(
(
hostname
,
port
)
)
self
.
sock
.
bind
(
address
)
self
.
sock
.
listen
(
5
)
self
.
sock
.
listen
(
5
)
self
.
clients
=
[]
self
.
clients
=
[]
...
@@ -197,4 +198,4 @@ class Client(Connection):
...
@@ -197,4 +198,4 @@ class Client(Connection):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
import
sys
import
sys
port
=
int
(
sys
.
argv
[
1
])
if
len
(
sys
.
argv
)
>
1
else
8000
port
=
int
(
sys
.
argv
[
1
])
if
len
(
sys
.
argv
)
>
1
else
8000
Server
(
port
,
loglevel
=
logging
.
DEBUG
).
run
()
Server
(
(
''
,
port
)
,
loglevel
=
logging
.
DEBUG
).
run
()
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