[Twisted-Python] txWS !!

Corbin Simpson cds at corbinsimpson.com
Sun Jul 1 06:03:44 EDT 2012


On Sat, Jun 30, 2012 at 09:36:08PM +0200, vinod kumar wrote:
> Hi,
> 
>  Thanks a lot for your reply. The trouble is that the events I have are
> triggered by a homematic CCU. The CCU does it by multicall which has not
> yet been implemented in twisted servers. So, I'm running a non-twisted
> xmlrpc server in a thread so that my CCU triggers the events and it's
> happening too. I can see the events printed on the console too. Now, I just
> want a way to write the same to sockets. Can't we connect these to txWS
> factory ? Doesn't the txWS has some socket object so that we can just say
> socket.write..hmm

Well, no, txWS doesn't have raw sockets like that. Let me try to ASCII
things out.

In a normal Twisted TCP server, you might have some situation like this:

+---------------------------+
| ServerFactory             |
|                           |           +----+
| + - - - - -+ +- - - - - + |~Raw~Bytes~|Port|~~TCP~~
| | Protocol | | Protocol | |           +----+
| +- - - - - + + - - - - -+ |
+---------------------------+

In this scenario, the Port is bound to a ServerFactory, and each
Protocol of the Factory corresponds to a single TCP client. Protocols
should contain all of the logic necessary for communicating with their
given client. If necessary, the Factory could track all of its
Protocols, in order to facilitate cross-Protocol communication.

So, with that in mind, here's what txWS provides:

+---------------------------+
| WebSocketsFactory         |
|                           |=WebSockets=Framing=+----+
| + - - - - - - - +         |~~~~~~Raw~Bytes~~~~~|Port|~~TCP~~
| | ServerFactory |         |====================+----+
| +- - - - - - - -+         |
+---------------------------+

That is, WebSocketsFactory wraps a ServerFactory and armors all of the
bytes being sent with WebSockets frames. There isn't any magic in there;
it's all compositional and very straightforward.

I'm not sure what you want when you say that you "want a way to write
the same to sockets." txWS doesn't have any special insight into the
bottom layer of its connection. (It could even work on non-TCP, if
somebody really wanted that.)

I hope this clarifies things; I know it doesn't exactly answer your
question as stated.

~ C.



More information about the Twisted-Python mailing list