2 servers on the bus
[email protected] Tue, 19 Feb 2019 04:58:16 -0800 (PST)
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_1061_1919689917.1550581096566
Content-Type: multipart/alternative;
boundary="----=_Part_1062_156970650.1550581096567"
------=_Part_1062_156970650.1550581096567
Content-Type: text/plain; charset="UTF-8"
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 cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
------=_Part_1062_156970650.1550581096567
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div></div><div><br></div><div>If possible at all I'd =
like to run two, more or less independent, servers on the bus exchanging me=
ssages. I'm struggling to get it to work, some sketchy code below.<br><=
br>How do I tie the receiver class to the receiver server and how do I do t=
he configuration per server and the global one?<br><br>Ingo<br><br><br><br>=
import cherrypy<br><br>class Receiver():<br><br>=C2=A0 @cherrypy.expose<br>=
=C2=A0 @cherrypy.tools.json_in()<br>=C2=A0 def incoming(self, **kwargs):<br=
>=C2=A0=C2=A0=C2=A0 """<br>=C2=A0=C2=A0=C2=A0 receives POSTe=
d data, pushes it onto the cherrypy bus<br>=C2=A0=C2=A0=C2=A0 ""&=
quot;<br>=C2=A0=C2=A0=C2=A0 input_json =3D cherrypy.request.json<br>=C2=A0=
=C2=A0=C2=A0 msg =3D "event: time\ndata: {}\n\n".format(str(input=
_json['cpu']))<br>=C2=A0=C2=A0=C2=A0 cherrypy.engine.publish("=
the_data", msg)<br>=C2=A0=C2=A0=C2=A0 return ""<br><br># app=
specific conf<br>srvReceiver =3D os.path.join(os.path.dirname(__file__), &=
#39;srvReceiver.conf')<br>cherrypy.tree.mount(Receiver(), '/', =
srvReceiver)<br><br><br>class Transmitter():<br><br>=C2=A0 @cherrypy.expose=
<br>=C2=A0 def outgoing(self):<br>=C2=A0=C2=A0=C2=A0 """<br>=
=C2=A0=C2=A0=C2=A0 publishes data from the subscribed channel...<br>=C2=A0=
=C2=A0=C2=A0 """<br>=C2=A0=C2=A0=C2=A0 channel =3D 'the_=
data'<br>=C2=A0=C2=A0=C2=A0 ... etc.<br><br>=C2=A0 @cherrypy.expose<br>=
=C2=A0 def index(self):<br>=C2=A0=C2=A0=C2=A0 return open('index.html&#=
39;)<br><br># app specific conf<br>srvTransmit =3D os.path.join(os.path.dir=
name(__file__), 'srvTransmit.conf')<br>cherrypy.tree.mount(Transmit=
(), '/', srvTransmit)<br><br>receiver =3D ServerAdapter(bus, receiv=
er.HTTPServer(host=3D'192.168.1.4', port=3D8080))<br>transmit =3D S=
erverAdapter(bus, transmit.HTTPServer(host=3D'192.168.1.4', port=3D=
8081))<br>receiver.subscribe()<br>transmit.subscribe()<br>bus.start()<br><b=
r><br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;cherrypy-users" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:cherrypy-users+unsubscribe-/[email protected]">cher=
rypy-users+unsubscribe-/[email protected]</a>.<br />
To post to this group, send email to <a href=3D"mailto:cherrypy-users@googl=
egroups.com">cherrypy-users-/[email protected]</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/group/cherrypy-use=
rs">https://groups.google.com/group/cherrypy-users</a>.<br />
For more options, visit <a href=3D"https://groups.google.com/d/optout">http=
s://groups.google.com/d/optout</a>.<br />
------=_Part_1062_156970650.1550581096567--
------=_Part_1061_1919689917.1550581096566--