469,268 Members | 1,019 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

How best to achieve asynchronous socket input and output?

I'm writing a wxPython telnet-like application that needs to be able
to send and receive data independently of each other. The asyncore
library comes close to what I want, but still requires I have a
blocked thread (the one that calls asyncore.loop() ). It also seems a
little unpredictable; one example of this is that when I based an
example around the sample HTTP client (11.23.1 in the docs),
handle_write never seemed to get called, and I had to call .send()
directly, bypassing any buffering.

Is there a better way of achieving what I want? Or something I need to
know about the asyncore library to get it to do this?

--
Ben Sizer
Jul 18 '05 #1
4 2738
On 23 Nov 2003 18:21:12 -0800, Kylotan <ky*****@hotmail.com> wrote:
I'm writing a wxPython telnet-like application that needs to be able
to send and receive data independently of each other. The asyncore
library comes close to what I want, but still requires I have a
blocked thread (the one that calls asyncore.loop() ). It also seems a
little unpredictable; one example of this is that when I based an
example around the sample HTTP client (11.23.1 in the docs),
handle_write never seemed to get called, and I had to call .send()
directly, bypassing any buffering.

Is there a better way of achieving what I want? Or something I need to
know about the asyncore library to get it to do this?


I usually jump immediately to select, which maps almost directly to select(2),
giving a lot of control, and lack of portability for non-unix systems.

In the context of GUI's, maybe you can get the eventloop of wxpython to
wait for file I/O on the sockets, some GUI libraries provide such a hook
(GUI handling in the end means waiting for data from the X11 server, ie
a select-like thing).
Otherwise you must poll, or use a seperate thread.

--
Albert
--
Unlike popular belief, the .doc format is not an open publically available format.
Jul 18 '05 #2
On Sun, Nov 23, 2003 at 06:21:12PM -0800, Kylotan wrote:
I'm writing a wxPython telnet-like application that needs to be able
to send and receive data independently of each other. The asyncore
library comes close to what I want, but still requires I have a
blocked thread (the one that calls asyncore.loop() ). It also seems a
little unpredictable; one example of this is that when I based an
example around the sample HTTP client (11.23.1 in the docs),
handle_write never seemed to get called, and I had to call .send()
directly, bypassing any buffering.

Is there a better way of achieving what I want? Or something I need to
know about the asyncore library to get it to do this?


You can use Twisted to do this, but unfortunately its builtin wxpython
support isn't very good. There is however a workaround for it:
http://aspn.activestate.com/ASPN/Coo.../Recipe/181780

(There's also a more comprehensive example app here:
http://aspn.activestate.com/ASPN/Coo.../Recipe/203471)

If you don't want to switch to Twisted, perhaps a similar approach would
work for asyncore?

-Andrew.
Jul 18 '05 #3
Kylotan wrote:
I'm writing a wxPython telnet-like application that needs to be able
to send and receive data independently of each other. The asyncore
library comes close to what I want, but still requires I have a
blocked thread (the one that calls asyncore.loop() ).


using a timer to poll asyncore tends to work pretty well.

for examples, see "Managing Downloads" and "Keeping the network
traffic going" on this page:

http://effbot.org/zone/effnews-3.htm

(you can search for "poll" to find the relevant portions)

</F>

Jul 18 '05 #4
"Fredrik Lundh" <fr*****@pythonware.com> wrote in message news:<ma*************************************@pyth on.org>...
Kylotan wrote:
I'm writing a wxPython telnet-like application that needs to be able
to send and receive data independently of each other. The asyncore
library comes close to what I want, but still requires I have a
blocked thread (the one that calls asyncore.loop() ).


using a timer to poll asyncore tends to work pretty well.

for examples, see "Managing Downloads" and "Keeping the network
traffic going" on this page:

http://effbot.org/zone/effnews-3.htm

(you can search for "poll" to find the relevant portions)


Ok, so from what you're saying, and what the others in the thread have
said, it seems like I can't get around having to poll the sockets
periodically somehow, in another thread. I guess I will just make a
thread for all my sockets and pass it relevant callbacks for whenever
select decides that a socket has some data incoming.

--
Ben Sizer
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Winston Nimchan | last post: by
1 post views Thread by Chan | last post: by
7 posts views Thread by Colin | last post: by
4 posts views Thread by Engineerik | last post: by
2 posts views Thread by Nicolas Le Gland | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.