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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • billie

    #1

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

    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

    #2
    Re: How to manage two (different) sockets without using threads?


    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:



    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

    Comment

    • Jordan

      #3
      Re: How to manage two (different) sockets without using threads?

      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?

      Comment

      • Bjoern Schliessmann

        #4
        Re: How to manage two (different) sockets without using threads?

        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

        Comment

        • Fredrik Lundh

          #5
          Re: How to manage two (different) sockets without using threads?

          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_downl oad class in this
          article for a start:



          </F>

          Comment

          Working...