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

B

billie

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?
 
M

Maksim Kasimov

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
 
J

Jordan

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.
 
B

Bjoern Schliessmann

billie said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top