2 servers on the bus

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

2 servers on the bus

ingoogni

If possible at all I'd like to run two, more or less independent, servers on the bus exchanging messages. I'm struggling to get it to work, some sketchy code below.

How do I tie the receiver class to the receiver server and how do I do the configuration per server and the global one?

Ingo



import cherrypy

class Receiver():

  @cherrypy.expose
  @cherrypy.tools.json_in()
  def incoming(self, **kwargs):
    """
    receives POSTed data, pushes it onto the cherrypy bus
    """
    input_json = cherrypy.request.json
    msg = "event: time\ndata: {}\n\n".format(str(input_json['cpu']))
    cherrypy.engine.publish("the_data", msg)
    return ""

# app specific conf
srvReceiver = os.path.join(os.path.dirname(__file__), 'srvReceiver.conf')
cherrypy.tree.mount(Receiver(), '/', srvReceiver)


class Transmitter():

  @cherrypy.expose
  def outgoing(self):
    """
    publishes data from the subscribed channel...
    """
    channel = 'the_data'
    ... etc.

  @cherrypy.expose
  def index(self):
    return open('index.html')

# app specific conf
srvTransmit = os.path.join(os.path.dirname(__file__), 'srvTransmit.conf')
cherrypy.tree.mount(Transmit(), '/', srvTransmit)

receiver = ServerAdapter(bus, receiver.HTTPServer(host='192.168.1.4', port=8080))
transmit = ServerAdapter(bus, transmit.HTTPServer(host='192.168.1.4', port=8081))
receiver.subscribe()
transmit.subscribe()
bus.start()


--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.