start a multi-sockets server (a socket/per thread) with different ports but same host
Jean-Paul Calderone
exarkun at divmod.com
Sun Aug 13 10:25:08 EDT 2006
On 12 Aug 2006 21:59:20 -0700, zxo102 <zxo102 at gmail.com> wrote:
>Jean-Paul,
> I just start to learn Twisted. Here is my simple case: I can find
>the data sent by clients in dataReceived but I don't know which
>client/which port the data is from. After I know where the data comes
>from, I can do different things there, for example, write them into
>different files via bsddb. I am not sure if it is the correct way to
>do it.
>
>
> def dataReceived(self, data):
> # Accumulate the new data in our list
> self.received.append(data)
> # And then echo the entire list so far back to the client
> self.transport.write(''.join(data))
>
> print "============> data: ", data
> print " which Port? : ", self.factory.port # unforunately it is
>an object here.
Check out self.transport.getHost(). It, too, is an object, with a 'port'
attribute.
You may also want to glance over the API documentation:
http://twistedmatrix.com/documents/current/api/
Jean-Paul
More information about the Python-list
mailing list