[Twisted-Python] txWS !!
vinod kumar
vk.86.811 at gmail.com
Sun Jul 1 07:09:53 EDT 2012
Hi,
Thanks a lot for your clarification. My problems have been resolved.
Actually, I shifted to Autobahn. It's way comfortable in editing the
examples there. Now, I got the way to deal with txWS too indeed. The answer
to what I asked is just about grabbing the endpoints and use them at times.
In Autobahn broadcast example, they store all the clients when the
connection is opened as shown below:
def onOpen(self):
self.factory.register(self)
And in factory, the register function is this way:
def register(self, client):
if not client in self.clients:
print "registered client " + client.peerstr
self.clients.append(client)
So, this way I can send to all clients whenever I want as follows:
......some code .....
for c in self.clients:
c.sendMessage(json_event)
......some code........
Anyways, I have implemented my scenario pretty well using Autobahn. I'm
sure I can do the same with txWS at times.
Thanks,
Vinodh
On Sun, Jul 1, 2012 at 12:03 PM, Corbin Simpson <cds at corbinsimpson.com>wrote:
> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20120701/4f95d9a1/attachment.htm
More information about the Twisted-Python
mailing list