By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,847 Members | 2,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,847 IT Pros & Developers. It's quick & easy.

How to manage two (different) sockets without using threads?

P: n/a
Hi all.
I'm (re)writing an FTP server application by using asyncore/asynchat
modules.
FTP tipically got two different channels: command and data.
I'm succesfully managing command channel through asynchat framework,
but I'm not sure about how to manage data channel without using a
thread/subprocess.
Is there an optimal to do that?
Can anyone point me in the right direction?

Dec 13 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

Hi, i don't know how to do it with asyncore/asynchat,
but it is possible to handle different sockets in one process by using "select" standard module:

for_reading, for_writing, where_errors =\
select.select( (<sockets list), ( <sockets list), (<sockets list>), 0)

you can find all necessary information in python documentation:
http://www.python.org/doc/2.4/lib/module-select.html
btw: "asyncore" use "select" for socket handling, take a look in asyncore.py
hope it helps
billie wrote:
Hi all.
I'm (re)writing an FTP server application by using asyncore/asynchat
modules.
FTP tipically got two different channels: command and data.
I'm succesfully managing command channel through asynchat framework,
but I'm not sure about how to manage data channel without using a
thread/subprocess.
Is there an optimal to do that?
Can anyone point me in the right direction?

--
Maksim Kasimov
Dec 13 '06 #2

P: n/a
Why are you trying to make this asynchronous? I think part of the point
of ftp using two sockets was to make it multithreaded. If you're going
to make it asynchronous, It's probably going to be easier to do the
"select"ing yourself, instead of relying on asyncore or asynchat.
Unless you have an insanely fast connection and/or really small files
on the server, using asynchronous socket handling is going to stop up
the server b/c select won't check the other sockets until the current
one is done with whatever it's doing.

billie wrote:
Hi all.
I'm (re)writing an FTP server application by using asyncore/asynchat
modules.
FTP tipically got two different channels: command and data.
I'm succesfully managing command channel through asynchat framework,
but I'm not sure about how to manage data channel without using a
thread/subprocess.
Is there an optimal to do that?
Can anyone point me in the right direction?
Dec 13 '06 #3

P: n/a
billie wrote:
I'm (re)writing an FTP server application by using
asyncore/asynchat modules.
FTP tipically got two different channels: command and data.
I'm succesfully managing command channel through asynchat
framework, but I'm not sure about how to manage data channel
without using a thread/subprocess.
Is there an optimal to do that?
I don't know much about asynchat, but I think it's been done for
this.

But if you want to save pain, try the Twisted framework.

Regards,
Björn

--
BOFH excuse #2:

solar flares

Dec 13 '06 #4

P: n/a
billie wrote:
I'm succesfully managing command channel through asynchat framework,
but I'm not sure about how to manage data channel without using a
thread/subprocess.
use a separate dispatcher instance for the data transfer. see the
ftp_handle_pasv_response method and async_ftp_download class in this
article for a start:

http://effbot.org/zone/asyncore-ftp-client.htm

</F>

Dec 13 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.