[Twisted-Python] txWS !!

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 Thanks, Vinodh ------------------------------------------------------------------- Hi Vinodh, txWS merely lets you connect to a Twisted Factory through WebSockets. You will still need to structure your code such that the events that you are responding to are connected to that Factory. It might be helpful to rewrite your XML-RPC server to use Twisted's XML-RPC (see http://twistedmatrix.com/documents/current/web/howto/xmlrpc.html for a tutorial on that) and then it will be easier to hook up your events without having to worry about threading or other blocking things. If you're having specific problems with txWS, let me know; it's important to us that txWS work smoothly for people using it. ~ C. ------------------------------- On Fri, Jun 29, 2012 at 04:52:06PM +0200, vinod kumar wrote:

On Sat, Jun 30, 2012 at 09:36:08PM +0200, vinod kumar wrote:
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.

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@corbinsimpson.com>wrote:

On Sat, Jun 30, 2012 at 09:36:08PM +0200, vinod kumar wrote:
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.

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@corbinsimpson.com>wrote:
participants (2)
-
Corbin Simpson
-
vinod kumar