[Twisted-Python] StdIO forwarding server
Matthew Glubb
matt at zgroupplc.com
Thu May 10 07:59:31 MDT 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Tomas,
If the clients are already connected, you should just be able send
your data as you describe.
If your clients are not connected to the server, your server factory
should be hosted by the client and it should listen for incoming
requests by your actual server.
Remember, the server factory creates a Protocol instance for *every*
client connected to it. What this means is that you will have one
server factory instance that listens for incoming connections. When a
connection occurs, ServerFactory.buildProtocol will be called,
creating a Protocol instance for that connection. Your protocol class
should take the form of a state machine that copes with being in a
listening or transmitting state. The other alternative is to use two
Protocol classes, one for the server and one for the client.
Having little experience of twisted and network programming in
general, it took a while for that to dawn on me. Hopefully I have
grasped it correctly, if not, I am sure that others on the list will
correct me :)
Hope that helps,
Matt
On 10 May 2007, at 14:03, Tomas Neme wrote:
> I need to write a server that receives a command through stdIO and
> forwards it to all of its clients. So far I've been able to create and
> mantain a list of clients, but I can't send the message to all of
> them.
>
> This might be confusing, I think I have a completely wrong approach. I
> used the echoclient.py example from O'Reilly's Network Programming
> Essentials, and simply changed the ClientFactory to a ServerFactory,
> added a clients list and changed
>
> def dataReceived(self,data):
> self.output.write(data)
>
> to
>
> def dataReceived(self,data):
> for c in self.factory.clients:
> c.output.write(data)
>
> but for some reason this comes out to the server's StdIO instead of
> the client's
>
> can anyone give me some tip?
>
> --
> |_|0|_|
> |_|_|0|
> |0|0|0|
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
m a t t h e w g l u b b
________________________________________________________________________
Z Group PLC
Tel: +44 (0) 8700 111 173
Fax: +44 (0) 8707 051 393
Txt: +44 (0) 7800 140 877
Web: <http://www.zgroupplc.com/>
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they are
addressed. The opinions expressed in this mail are those of the author
and do not necessarily represent the views of the company. If you have
received this email in error please notify <service at zgroupplc.com>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
iD8DBQFGQyVGyI6MkdKPngkRAgl1AKCzWua9rxmOnryL0XVSdAuwQLsb/gCcDasa
eKcyhV01VDpBGBGuI4YVssE=
=G9nQ
-----END PGP SIGNATURE-----
More information about the Twisted-Python
mailing list