[Twisted-Python] Example for a new protocol over TCP
Hi, I'm new to twisted and I'm trying to implement a set of protocols (already available in Java, JXSE). I lamost know how I will set up the different services that will communicate through the reactor, but I'm starting from the beginning, so here is my real question. How can I set up a factory (using a TCP protocol) so that when I want to send a message to someone, it connects though TCP to the other computer, they exchange a welcome message, and only then the message is sent though the TCP protocol ? Of course, it is not as simple as this, but if someone has a pointer, I will be able to fill the missing pieces in my design ;) Thanks, Matthieu -- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher
Hi again, Does someone have a pointer ? It should be enough for me to start with ;) I thought about this: - creation of the client - initialization of the messenger - when building the messenger, I create a DeferredList (or something like that) - when sending a message, I call a send() method that will either add the message to the DeferredList or directly send() is the DeferredList was processed. - when the initialization is complete, the DeferredList is processed. Is this realistic? Matthieu 2008/6/18 Matthieu Brucher <matthieu.brucher@gmail.com>:
Hi,
I'm new to twisted and I'm trying to implement a set of protocols (already available in Java, JXSE). I lamost know how I will set up the different services that will communicate through the reactor, but I'm starting from the beginning, so here is my real question. How can I set up a factory (using a TCP protocol) so that when I want to send a message to someone, it connects though TCP to the other computer, they exchange a welcome message, and only then the message is sent though the TCP protocol ? Of course, it is not as simple as this, but if someone has a pointer, I will be able to fill the missing pieces in my design ;)
Thanks, Matthieu -- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher
-- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher
On Wed, 25 Jun 2008 20:28:36 +0200, Matthieu Brucher <matthieu.brucher@gmail.com> wrote:
Hi again,
Does someone have a pointer ? It should be enough for me to start with ;) I thought about this: - creation of the client
Documentation for creating a client is here: http://twistedmatrix.com/projects/core/documentation/howto/clients.html
- initialization of the messenger - when building the messenger, I create a DeferredList (or something like that) - when sending a message, I call a send() method that will either add the message to the DeferredList or directly send() is the DeferredList was processed. - when the initialization is complete, the DeferredList is processed.
These parts, I don't understand. Jean-Paul
- initialization of the messenger - when building the messenger, I create a DeferredList (or something like that) - when sending a message, I call a send() method that will either add the message to the DeferredList or directly send() is the DeferredList was processed. - when the initialization is complete, the DeferredList is processed.
These parts, I don't understand.
Thanks for the answer ;) I've already printed and read the complete tutorial, but I may have missed something. In my application, I have a pool of peer addresses and I may have another pool of peer connections (other clients/peers may have connected to my own TCP server or I'm already connected to them, this would be handled by the factory). Then I want to send a message to one of the peers though one of its addresses in the pool (this will even get harder, as there may be different servers listening to different interfaces, I don't know if twisted manages this). For this purpose, I'd like to have something like:
self.get_messenger(peer_address).send(message)
This would look for a connection to this peer address in the peer connections pool if it is already available, or it will try to connect to the remote peer address. As it is not a simple TCP connection, before sending the actual message, several protocol messages are sent from the client to the server and vice-versa. Only then, when those messages are exchanged, I can actually send the real message to the remote peer. Is it more clear ? It may not be the simplest way of doing stuff, but the principle behond the protocols I use (which are already impelemnted in C and Java) is to hide the connection to a remote peer, and to have a message queue, so twisted seems to be the best tool for this. Cheers, Matthieu -- French PhD student Website : http://matthieu-brucher.developpez.com/ Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn : http://www.linkedin.com/in/matthieubrucher
participants (2)
-
Jean-Paul Calderone -
Matthieu Brucher