start a multi-sockets server (a socket/per thread) with different ports but same host

Jean-Paul Calderone exarkun at divmod.com
Sat Aug 12 18:57:31 EDT 2006


On 12 Aug 2006 10:44:29 -0700, zxo102 <zxo102 at gmail.com> wrote:
>Jean-Paul,
>Thanks a lot. The code is working. The python twisted is new to me too.
>Here are my three more questions:
>1. Since the code need to be started in a wxpyhon GUI (either by
>clicking a button or up with the GUI),  do I have to run the code in a
>thread (sorry, I have not tried it yet)?

You can try to use Twisted's wxPython integration support:

http://twistedmatrix.com/projects/core/documentation/howto/choosing-reactor.html#auto15

But note the warnings about how well it is likely to work.  Using a separate
thread might be the best solution.

>2. How can I grab the client data in the code? Can you write two lines
>for that? I really appreciate that.

I'm not sure what you mean.  The data is available in the `received' attribute
of the protocol instance.  Any code which needs to manipulate the data can get
that list and do whatever it likes with it.

>3. After I change
>self.transport.write(''.join(self.data))
>   to
>self.transport.write(''.join(data))
>  and scan all the ports with the following code twice (run twice).
>First round scanning says "succefully connected". But second round
>scanning says "failed". I have to restart your demo code to make it
>work.

I intentionally added code which shuts the server off after the first round
of connections is completed, since that seemed to be what your example
program was doing.  If you don't want this, just remove the shutdown code.

Jean-Paul



More information about the Python-list mailing list