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
dbe4eecf
Commit
dbe4eecf
authored
Aug 22, 2013
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved Server contructor arguments
parent
c140e422
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
11 deletions
+12
-11
server.py
server.py
+10
-9
test/server.py
test/server.py
+2
-2
No files found.
server.py
View file @
dbe4eecf
...
@@ -31,8 +31,8 @@ class Server(object):
...
@@ -31,8 +31,8 @@ class Server(object):
>>> EchoServer(('', 8000)).run()
>>> EchoServer(('', 8000)).run()
"""
"""
def
__init__
(
self
,
address
,
loglevel
=
logging
.
INFO
,
protocols
=
[]
,
def
__init__
(
self
,
address
,
loglevel
=
logging
.
INFO
,
ssl_args
=
None
,
secure
=
False
,
max_join_time
=
2.0
,
**
kwargs
):
max_join_time
=
2.0
,
**
kwargs
):
"""
"""
Constructor for a simple web socket server.
Constructor for a simple web socket server.
...
@@ -45,10 +45,11 @@ class Server(object):
...
@@ -45,10 +45,11 @@ class Server(object):
`protocols` and `extensions` are passed directly to the websocket
`protocols` and `extensions` are passed directly to the websocket
constructor.
constructor.
`secure` is a flag indicating whether the server is SSL enabled. In
`ssl_args` is a dictionary with arguments for `websocket.enable_ssl`
this case, `keyfile` and `certfile` must be specified. Any additional
(and thus to ssl.wrap_socket). If omitted, the server is not
keyword arguments are passed to `websocket.enable_ssl` (and thus to
SSL-enabled. If specified, at least the dictionary keys "keyfile" and
`ssl.wrap_socket`).
"certfile" must be present because these are required arguments for
`websocket.enable_ssl` for a server 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.
...
@@ -61,11 +62,11 @@ class Server(object):
...
@@ -61,11 +62,11 @@ class Server(object):
hostname
,
port
=
address
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
(
protocols
=
protocols
,
extensions
=
extension
s
)
self
.
sock
=
websocket
(
**
kwarg
s
)
self
.
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
self
.
sock
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
if
s
ecure
:
if
s
sl_args
:
self
.
sock
.
enable_ssl
(
server_side
=
True
,
**
kw
args
)
self
.
sock
.
enable_ssl
(
server_side
=
True
,
**
ssl_
args
)
self
.
sock
.
bind
(
address
)
self
.
sock
.
bind
(
address
)
self
.
sock
.
listen
(
5
)
self
.
sock
.
listen
(
5
)
...
...
test/server.py
View file @
dbe4eecf
...
@@ -16,6 +16,6 @@ class EchoServer(Server):
...
@@ -16,6 +16,6 @@ class EchoServer(Server):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
EchoServer
(
8000
,
'localhost'
,
EchoServer
(
(
'localhost'
,
8000
)
,
#s
ecure=True, keyfile='cert.pem', certfile='cert.pem'
,
#s
sl_args=dict(keyfile='cert.pem', certfile='cert.pem')
,
loglevel
=
logging
.
DEBUG
).
run
()
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