[Twisted-Python] session management
![](https://secure.gravatar.com/avatar/6ab0346b5fe72e5fb73adc5b232e1299.jpg?s=120&d=mm&r=g)
Greetings, I am new to this list and twisted. I have worked with some systems similar to twisted, notably Apache MINA. I am trying to find out how to set up my server to support sessions for multiple clients. Right now I am simply developing a telnet-like application to learn twisted but cannot figure out how to manage sessions for the remote clients. Thanks, Mark
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 04:10 am, elihusmails@gmail.com wrote:
Protocol instances are normal Python objects. You can use normal Python attributes on them in the normal way. For example: from twisted.internet.protocol import Protocol class Counter(Protocol): """ Keep track of how many times data is delivered over a connection. """ def connectionMade(self): self.count = 0 def dataReceived(self, bytes): self.count += 1 Jean-Paul
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 02:38 am, elihusmails@gmail.com wrote:
The protocol instance *is* the session (or, as I would normally say "the protocol instance has a one to one relationship with a connection", but I think that's what you mean when you say "the session"). You can define whichever methods and attributes you want. It's a regular Python object. All the regular stuff you know about Python objects applies. Jean-Paul
![](https://secure.gravatar.com/avatar/3c1b6ecd94f7124c21dc21ab96d14a8d.jpg?s=120&d=mm&r=g)
I found the following example answered my question: http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#HowdoImakeinputo... Good luck. Mark On Mar 31, 2010 12:11 AM, "Mark" <elihusmails@gmail.com> wrote: I figured as much that twisted supported the notion of sessions. Are there any examples that show me how to access them and add/remove/update attributes in the session? On Tue, Mar 30, 2010 at 6:42 PM, Itamar Turner-Trauring <itamar@itamarst.org> wrote:
Greetings...
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 04:10 am, elihusmails@gmail.com wrote:
Protocol instances are normal Python objects. You can use normal Python attributes on them in the normal way. For example: from twisted.internet.protocol import Protocol class Counter(Protocol): """ Keep track of how many times data is delivered over a connection. """ def connectionMade(self): self.count = 0 def dataReceived(self, bytes): self.count += 1 Jean-Paul
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 02:38 am, elihusmails@gmail.com wrote:
The protocol instance *is* the session (or, as I would normally say "the protocol instance has a one to one relationship with a connection", but I think that's what you mean when you say "the session"). You can define whichever methods and attributes you want. It's a regular Python object. All the regular stuff you know about Python objects applies. Jean-Paul
![](https://secure.gravatar.com/avatar/3c1b6ecd94f7124c21dc21ab96d14a8d.jpg?s=120&d=mm&r=g)
I found the following example answered my question: http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#HowdoImakeinputo... Good luck. Mark On Mar 31, 2010 12:11 AM, "Mark" <elihusmails@gmail.com> wrote: I figured as much that twisted supported the notion of sessions. Are there any examples that show me how to access them and add/remove/update attributes in the session? On Tue, Mar 30, 2010 at 6:42 PM, Itamar Turner-Trauring <itamar@itamarst.org> wrote:
Greetings...
participants (4)
-
exarkun@twistedmatrix.com
-
Itamar Turner-Trauring
-
Mark
-
Mark Bailey