Created
June 17, 2015 00:07
-
-
Save prologic/8204f5022a02b690727d to your computer and use it in GitHub Desktop.
UNIX Server answering SO Q http://stackoverflow.com/questions/30880183/how-to-identify-a-client-connected-to-af-unix-socket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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