Re: UDP reading on multiple sockets

2009-05-22 Thread Lawrence D'Oliveiro
In message <27bd949f-80b5-44c9-8e3b-
c12b49c7e...@r34g2000vbi.googlegroups.com>, thomas.vo...@likeabird.de wrote:

> The only honest answer would be that I'm totaly unfamiliar with select
> and also the documentation I found wasn't able to clear the picture.
> So are there examples of using select together with sockets available?

select is easy to use. In Python, you just pass it three lists of file-like 
objects (anything that implements fileno in the way described in the docs), 
together with an optional timeout. It will return three corresponding lists, 
being subsets of the ones you passed (which might all be empty if the 
timeout expired). You then just go through each item in each returned list, 
doing reads (or accepts, as appropriate) from the files that have something 
waiting to be read, writing to the ones waiting for something to be written, 
and perhaps reporting errors and closing the ones that report problems. 
That's basically all there is to it.

This example, of how do implement a timeout on I/O 
, is in C, but 
it should help you get the idea.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UDP reading on multiple sockets

2009-05-19 Thread Gabriel Rossetti

thomas.vo...@likeabird.de wrote:

On 17 Mai, 04:22, Grant Edwards  wrote:
  

On 2009-05-17, Thomas Vogel  wrote:



I'm currently have the problem that I try to read UDP messages from
multiple sockets in parallel. So let's say I get UDP packets from the
same IP on the ports 2000, 2001, 2002,...
  

Is there any reason you can't do it the easy way by using
select?

http://docs.python.org/library/select.html

--
Grant



The only honest answer would be that I'm totaly unfamiliar with select
and also the documentation I found wasn't able to clear the picture.
So are there examples of using select together with sockets available?

Kind regards
Thomas
  

You could also try Twisted : http://twistedmatrix.com/trac/

Best,
Gabriel
--
http://mail.python.org/mailman/listinfo/python-list


Re: UDP reading on multiple sockets

2009-05-19 Thread Steve Howell
On May 18, 6:19 am, thomas.vo...@likeabird.de wrote:
> On 17 Mai, 04:22, Grant Edwards  wrote:
>
> > On 2009-05-17, Thomas Vogel  wrote:
>
> > > I'm currently have the problem that I try to read UDP messages from
> > > multiple sockets in parallel. So let's say I get UDP packets from the
> > > same IP on the ports 2000, 2001, 2002,...
>
> > Is there any reason you can't do it the easy way by using
> > select?
>
> >http://docs.python.org/library/select.html
>
> > --
> > Grant
>
> The only honest answer would be that I'm totaly unfamiliar with select
> and also the documentation I found wasn't able to clear the picture.
> So are there examples of using select together with sockets available?
>

My two cents on this issue is that you should stick with asyncore for
now and just figure out how to debug better what's going on.

I understand the rationale behind the alternatives--there are
certainly advantages (even in debugging) to using something closer to
the metal, like select, or in using something that might be a better
abstraction, like Twisted.

But really, if you look at the source code for asyncore, it's just a
thin layer on top of select.select, and the entire module is under 600
lines of code.  Asyncore is much maligned, and there are some
legitimate beefs with it, but it does well, for the most part, what it
intends to do, which is to solve some of the more difficult, or at
least tedious, problems with regards to dealing with select.select.

My fear is that if you try to do this without asyncore, via select,
you'll end up reinventing lots of asyncore with lots of your own
bugs.  I have less fear about going higher in the stack, except that
it just puts another layer on top of the problem, and I think the
issue you're dealing with is fairly low-level.

So my suggestion is to figure out a good debugging strategy, either by
getting a bit more familiar with asyncore internals (with a debugger,
print statements, analysis, etc.), or by better using system tools
(like snoop, truss, etc.) to see what's happening at the I/O level, or
both.

Good luck!



Steve


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UDP reading on multiple sockets

2009-05-19 Thread Jean-Paul Calderone

On Mon, 18 May 2009 06:19:01 -0700 (PDT), thomas.vo...@likeabird.de wrote:

On 17 Mai, 04:22, Grant Edwards  wrote:

On 2009-05-17, Thomas Vogel  wrote:

> I'm currently have the problem that I try to read UDP messages from
> multiple sockets in parallel. So let's say I get UDP packets from the
> same IP on the ports 2000, 2001, 2002,...

Is there any reason you can't do it the easy way by using
select?

http://docs.python.org/library/select.html

--
Grant


The only honest answer would be that I'm totaly unfamiliar with select
and also the documentation I found wasn't able to clear the picture.
So are there examples of using select together with sockets available?



You might find Twisted easier to use correctly than the select module.
You can find some basic Twisted/UDP documentation here:

 http://twistedmatrix.com/projects/core/documentation/howto/udp.html

You can trivially change the first example to handle multiple sockets -
just add more reactor.listenUDP calls.

Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: UDP reading on multiple sockets

2009-05-19 Thread Grant Edwards
On 2009-05-18, thomas.vo...@likeabird.de  wrote:
> On 17 Mai, 04:22, Grant Edwards  wrote:
>> On 2009-05-17, Thomas Vogel  wrote:
>>
>> > I'm currently have the problem that I try to read UDP messages from
>> > multiple sockets in parallel. So let's say I get UDP packets from the
>> > same IP on the ports 2000, 2001, 2002,...
>>
>> Is there any reason you can't do it the easy way by using
>> select?
>>
>> http://docs.python.org/library/select.html
>
> The only honest answer would be that I'm totaly unfamiliar
> with select and also the documentation I found wasn't able to
> clear the picture. So are there examples of using select
> together with sockets available?

http://www.google.com/search?q=python+select+example

http://www.amk.ca/python/howto/sockets/
http://code.activestate.com/recipes/531824/
http://mail.python.org/pipermail/python-list/2001-February/071302.html
http://squirl.nightmare.com/medusa/async_sockets.html

-- 
Grant

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UDP reading on multiple sockets

2009-05-19 Thread Guido Goldstein

Hi!

On Mon, 18 May 2009 06:19:01 -0700 (PDT)
  thomas.vo...@likeabird.de wrote:
[...]
> The only honest answer would be that I'm totaly unfamiliar with select
> and also the documentation I found wasn't able to clear the picture.
> So are there examples of using select together with sockets available?

If you want to write something related to networks you should know
this book:
  http://www.kohala.com/start/unpv12e.html
Also found at
  http://www.amazon.de/UNIX-Network-Programming-Sockets-Networking/dp/013490012X

MfT
  Guido
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UDP reading on multiple sockets

2009-05-19 Thread thomas . vogel
On 17 Mai, 04:22, Grant Edwards  wrote:
> On 2009-05-17, Thomas Vogel  wrote:
>
> > I'm currently have the problem that I try to read UDP messages from
> > multiple sockets in parallel. So let's say I get UDP packets from the
> > same IP on the ports 2000, 2001, 2002,...
>
> Is there any reason you can't do it the easy way by using
> select?
>
> http://docs.python.org/library/select.html
>
> --
> Grant

The only honest answer would be that I'm totaly unfamiliar with select
and also the documentation I found wasn't able to clear the picture.
So are there examples of using select together with sockets available?

Kind regards
Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UDP reading on multiple sockets

2009-05-16 Thread Grant Edwards
On 2009-05-17, Thomas Vogel  wrote:

> I'm currently have the problem that I try to read UDP messages from 
> multiple sockets in parallel. So let's say I get UDP packets from the 
> same IP on the ports 2000, 2001, 2002,...

Is there any reason you can't do it the easy way by using
select?

http://docs.python.org/library/select.html

-- 
Grant

-- 
http://mail.python.org/mailman/listinfo/python-list