[Twisted-Python] session management
Mark
elihusmails at gmail.com
Fri Apr 2 07:17:31 MDT 2010
Thanks. My confusion is just in the naming of things...
On Thu, Apr 1, 2010 at 11:09 PM, <exarkun at twistedmatrix.com> wrote:
> On 02:38 am, elihusmails at gmail.com wrote:
>>
>> On Wed, Mar 31, 2010 at 5:39 PM, <exarkun at twistedmatrix.com> wrote:
>>>
>>> On 04:10 am, elihusmails at gmail.com wrote:
>>>>
>>>> On Tue, Mar 30, 2010 at 6:42 PM, Itamar Turner-Trauring
>>>> <itamar at itamarst.org> wrote:
>>>>>>
>>>>>> 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.
>>>>>
>>>>> Each Protocol instance stays alive for the lifetime of the connection
>>>>> it
>>>>> is matched to (via the transport). So just store attributes on the
>>>>> Protocol instance.
>>>>
>>>> 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?
>>>
>>> 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
>>
>> Thanks for the help, but how do I access the session? What would be
>> the method call to put the data into a session for instance?
>
> 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
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>
More information about the Twisted-Python
mailing list