twisted python separation of data between protocols -
A new protocol is created each time the connection is created, but I can create two types of data sharing between two types Seeing.
In short I have defined a class that will use for each protocol state Protocol it immediately However each connection seems to get the same example of the JSONCollector Land, when I added the following statements to obtain the data. Self.transport.write (str (self.json_collector.char_buffer)) self.transport.write (str (self)) I get the following: Connection 1: 0x 968ae2c String IO.StringIO Example & gt; 0x969036c & gt; Connection 2: string IO.StringIO example at 0x968ae2c & lt; Chief . JSN Protocol Example & gt; 0x969068c Every time I type in text, text written from other text (connections) is displayed. So it seems that some strange reason StringIO () examples are shared, am I forgetting something I think I can use a factory to separate buffer by Adrar and make sure that Each protocol uses its buffer only, but without the need to store the storage I will not run through hoops thanks. P> this: Looks like an error, and instead of your source of troubles, try it: Otherwise, unlike a copy example, creating a
class JSONProtocol (protocol.Protocol) : Def __init__ (self): self.json_collector = JSONCollector () def data received (self, data): self.json_collector.process_data (data) self.transport.write (str (self))
class JSONCollector (): char_buffer = StringIO.StringIO)
class JSONCollector (): def __init __ (auto ): Self.char_buffer = StringIO.StringIO ()
char_buffer for the whole class type
Comments
Post a Comment