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
e1d8e4e7
Commit
e1d8e4e7
authored
May 15, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved server stuff into new section in README
parent
364f446c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
22 deletions
+25
-22
README.md
README.md
+24
-21
server.py
server.py
+1
-1
No files found.
README.md
View file @
e1d8e4e7
...
...
@@ -111,34 +111,37 @@ Basic usage
conn.send(msg(foo='Hello, World!'))
-
The built-in
`Server`
implementation is very basic. It starts a new thread
with a
`Connection.receive_forever()`
loop for each client that connects. It
also handles client crashes properly. By default, a
`Server`
instance only
logs every event using Python's
`logging`
module. To create a custom server,
The
`Server`
class should be extended and its event handlers overwritten. The
event handlers are named identically to the
`Connection`
event handlers, but
they also receive an additional
`client`
argument. This argument is a
modified
`Connection`
instance, so you can invoke
`send()`
and
`recv()`
.
Built-in Server
===============
For example, the
`EchoConnection`
example above can be rewritten to:
The built-in
`Server`
implementation is very basic. It starts a new thread with
a
`Connection.receive_forever()`
loop for each client that connects. It also
handles client crashes properly. By default, a
`Server`
instance only logs
every event using Python's
`logging`
module. To create a custom server, The
`Server`
class should be extended and its event handlers overwritten. The event
handlers are named identically to the
`Connection`
event handlers, but they
also receive an additional
`client`
argument. This argument is a modified
`Connection`
instance, so you can invoke
`send()`
and
`recv()`
.
import wspy
For example, the
`EchoConnection`
example above can be rewritten to:
class EchoServer(wspy.Server):
def onopen(self, client):
print 'Client %s connected' % client
import wspy
def onmessage(self, client, message):
print 'Received message "%s"' % message.payload
client.send(wspy.TextMessage(message.payload))
class EchoServer(wspy.Server):
def onopen(self, client):
print 'Client %s connected' % client
def onmessage(self, client, message):
print 'Received message "%s"' % message.payload
client.send(wspy.TextMessage(message.payload))
def onclose(self, client, code, reason):
print 'Client %s disconnected' % client
def onclose(self, client, code, reason):
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
`KeyboardInterrupt`
raised when this happens is caught by the server.
The server can be stopped by typing CTRL-C in the command line. The
`KeyboardInterrupt`
raised when this happens is caught by the server.
Extensions
...
...
server.py
View file @
e1d8e4e7
...
...
@@ -25,7 +25,7 @@ class Server(object):
>>> print 'Received message "%s"' % message.payload
>>> client.send(wspy.TextMessage(message.payload))
>>> def onclose(self, client):
>>> def onclose(self, client
, code, reason
):
>>> print 'Client %s disconnected' % client
>>> EchoServer(('', 8000)).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