Advertisement
Guest User

Client

a guest
Sep 15th, 2014
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. #!/usr/bin/python -i
  2.  
  3.  
  4. """Node Example
  5.  
  6. To use this example run it interactively through the Python interactive
  7. shell using the -i option as per the shebang line above.
  8.  
  9. i.e: python -i hello_node.py host port
  10.  
  11. At the python prompt:
  12.  
  13.    >>> x = app.fire(hello())
  14.    >>> <Hello[*.hello] ( )>
  15.  
  16.    >>> x
  17.    <Value ('Hello World! (16030)') result: True errors: False for <Hello[*.hello] ( )>
  18.    >>> y = app.fire(remote(hello(), "test"))
  19.    .
  20.    .
  21.    .
  22.    >>> y
  23.    <Value (u'Hello World! (16035)') result: True errors: False for <Remote[*.remote] (<Hello[.hello] ( )>, 'app2' channel=None)>
  24. """  # noqa
  25.  
  26.  
  27. from __future__ import print_function
  28.  
  29. import sys
  30. from os import getpid
  31.  
  32.  
  33. from circuits import Component, Event, Debugger
  34. from circuits.node import Node, remote  # noqa
  35.  
  36.  
  37. class hello(Event):
  38.     """hello Event"""
  39.     success = True
  40.  
  41.  
  42. class App(Component):
  43.  
  44.     def ready(self, client):
  45.         print("Ready!")
  46.  
  47.     def connected(self, host, port):
  48.         print("Connected to {}:{}".format(host, port))
  49.         self.fire(hello())
  50.  
  51.     def hello(self):
  52.         self.fire(remote(hello(), "test"))
  53.        
  54.     def hello_success(self, evt, result):
  55.         print(result)
  56.  
  57.  
  58. # Setup app1 with a debugger
  59. app = App()
  60. node = Node().register(app)
  61.  
  62. #Debugger().register(app)
  63.  
  64. host = sys.argv[1]
  65. port = int(sys.argv[2])
  66. bind = (host, port)
  67.  
  68. # Add an address of a node to talk to called "test"
  69. node.add("test", *bind)
  70.  
  71. # Start app as a thread
  72. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement