asyncore/asynchat

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • F.G.Testa

    asyncore/asynchat

    Hi!
    Is there a way to access a specific connected socket when using a derived
    asyncore.dispat cher and derived asynchat.async_ chat?

    class AcmeServer(asyn core.dispatcher ):
    def __init__(self, port):
    self.create_soc ket(socket.AF_I NET, socket.SOCK_STR EAM)
    self.bind(("", port))
    self.listen(5)

    def handle_accept(s elf):
    conn, addr = self.accept()
    AcmeChannel(sel f, conn, addr)

    def handle_close(se lf):
    print 'Server closed'

    def handle_error(se lf):
    print 'Server error'

    How do I access the underlying list/map/array of AcmeChannel?
    Thank you.




  • Jeremy Fincher

    #2
    Re: asyncore/asynchat

    "F.G.Testa" <testa@allos.sy tes.net> wrote in message news:<mailman.7 45.1068839049.7 02.python-list@python.org >...[color=blue]
    > How do I access the underlying list/map/array of AcmeChannel?
    > Thank you.[/color]

    There is none, but feel free to keep one yourself; I've done that, for
    instance, when I want to limit the number of connections to a server
    that should (barring malicious clients) have very fast sessions.

    Jeremy

    Comment

    • F.G.Testa

      #3
      Re: asyncore/asynchat

      But how do you keep it updated since we don't receive any notifications of
      closing/removing channels from asyncore/asynchat?
      I've found this: asyncore.socket _map (asyncore.py:62 ). It is a map of your
      inherited asynchat class and I'm using it to search for a specific channel
      and send data to it, but having my own dictionary would be more elegant, I
      think.

      "Jeremy Fincher" <tweedgeezer@ho tmail.com> wrote in message
      news:698f09f8.0 311141355.2430c 07b@posting.goo gle.com...[color=blue]
      > "F.G.Testa" <testa@allos.sy tes.net> wrote in message[/color]
      news:<mailman.7 45.1068839049.7 02.python-list@python.org >...[color=blue][color=green]
      > > How do I access the underlying list/map/array of AcmeChannel?
      > > Thank you.[/color]
      >
      > There is none, but feel free to keep one yourself; I've done that, for
      > instance, when I want to limit the number of connections to a server
      > that should (barring malicious clients) have very fast sessions.
      >
      > Jeremy
      > --
      > http://mail.python.org/mailman/listinfo/python-list
      >[/color]




      Comment

      • Jeremy Fincher

        #4
        Re: asyncore/asynchat

        "F.G.Testa" <testa@allos.sy tes.net> wrote in message news:<mailman.7 94.1069075944.7 02.python-list@python.org >...[color=blue]
        > But how do you keep it updated since we don't receive any notifications of
        > closing/removing channels from asyncore/asynchat?
        > I've found this: asyncore.socket _map (asyncore.py:62 ). It is a map of your
        > inherited asynchat class and I'm using it to search for a specific channel
        > and send data to it, but having my own dictionary would be more elegant, I
        > think.[/color]

        For my purposes I didn't need to keep it updated. Why why do you need
        access to such a dictionary? Is the channel itself unable to decide
        when it needs to send information?

        Jeremy

        Comment

        • MetalOne

          #5
          Re: asyncore/asynchat

          A map argument may be passed to asyncore.loop()
          asyncore.socket _map constains either a reference to the argument
          passed to asyncore.loop() or a global map object.
          asyncore.socket _map contains all the connections.

          You may also keep track of connections yourself by handling the
          callback functions
          asyncore.handle _accept()
          asyncore.handle _connect()
          aysncore.handle _close()

          Comment

          Working...