Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/python -i
import logging
import time
from os import getpid
from circuits import Component, Event, Debugger
from circuits.node import Node, remote
# Logging
format='%(asctime)s %(name)s %(levelname)s %(process)d %(funcName)s() %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p'
logger = logging.getLogger("test")
class hello(Event):
"""hello Event"""
class App(Component):
connection_status = False
def init(self):
def ready(self, client):"App : Ready!")
def connected(self, host, port):"App : Connected to {}:{}".format(host, port))
self.connection_status = True
# Work
hello_value = yield, "test"))"App -> X : {hello_value}".format(hello_value=hello_value))
def hello(self):
return "App : Hello World from a node! ({0:d})".format(getpid())
class NodeServer(Component):
def init(self):
"""Initialize our ``ChatServer`` Component.
This uses the convenience ``init`` method which is called after the
component is proeprly constructed and initialized and passed the
same args and kwargs that were passed during construction.
self.clients = {}
port = 9999
address = ""
Node(port=port, server_ip=address).register(self)"NodeServer : init done")
def connect(self, sock, host, port):
"""Connect Event -- Triggered for new connecting clients""""NodeServer client connect")
self.clients[sock] = {
"host": sock,
"port": port,
def disconnect(self, sock):
"""Disconnect Event -- Triggered for disconnecting clients"""
if sock not in self.clients:
del self.clients[sock]
def ready(self, server, bind):"NodeServer : Ready! Listening on {}:{}".format(*bind))"NodeServer : Waiting for remote events...")
def hello(self):"NodeServer hello")
return "NodeServer : Hello World from server! ({0:d})".format(getpid())
if __name__ == "__main__":
# Server
serv = NodeServer()
# Client
app = App()
node = Node().register(app)
bind = ("", 9999)
node.add("test", *bind)
while not app.connection_status:
time.sleep(1)"waiting to start...")"started")
#Don't work
x =,"test"))"Main -> X : {x}".format(x=x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.