Skip to content

Instantly share code, notes, and snippets.

@prologic
Created June 17, 2015 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prologic/8204f5022a02b690727d to your computer and use it in GitHub Desktop.
Save prologic/8204f5022a02b690727d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""Simple UNIX Echo Server
This example shows how you can create a simple UNIX Server (an Echo Service)
utilizing the builtin Socket Components that the circuits library ships with.
"""
from circuits import handler, Debugger
from circuits.net.sockets import UNIXServer
class EchoServer(UNIXServer):
@handler("connect")
def on_connect(self, sock, *peer):
print sock
print sock.fileno()
print peer
@handler("read")
def on_read(self, sock, data):
"""Read Event Handler
This is fired by the underlying Socket Component when there has been
new data read from the connected client.
..note :: By simply returning, client/server socket components listen
to ValueChagned events (feedback) to determine if a handler
returned some data and fires a subsequent Write event with
the value returned.
"""
return data
# Start and "run" the system.
# Bind to a UNIX Socket at /tmp/test.sock
app = EchoServer("/tmp/test.sock")
Debugger().register(app)
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment