asyncore/asynchat

Discussion in 'Python' started by F.G.Testa, Nov 14, 2003.

  1. F.G.Testa

    F.G.Testa Guest

    Hi!
    Is there a way to access a specific connected socket when using a derived
    asyncore.dispatcher and derived asynchat.async_chat?

    class AcmeServer(asyncore.dispatcher):
    def __init__(self, port):
    self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
    self.bind(("", port))
    self.listen(5)

    def handle_accept(self):
    conn, addr = self.accept()
    AcmeChannel(self, conn, addr)

    def handle_close(self):
    print 'Server closed'

    def handle_error(self):
    print 'Server error'

    How do I access the underlying list/map/array of AcmeChannel?
    Thank you.
     
    F.G.Testa, Nov 14, 2003
    #1
    1. Advertising

  2. "F.G.Testa" <> wrote in message news:<>...
    > How do I access the underlying list/map/array of AcmeChannel?
    > Thank you.


    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
     
    Jeremy Fincher, Nov 14, 2003
    #2
    1. Advertising

  3. F.G.Testa

    F.G.Testa Guest

    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" <> wrote in message
    news:...
    > "F.G.Testa" <> wrote in message

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

    >
    > 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
    >
     
    F.G.Testa, Nov 17, 2003
    #3
  4. "F.G.Testa" <> wrote in message news:<>...
    > 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.


    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
     
    Jeremy Fincher, Nov 17, 2003
    #4
  5. F.G.Testa

    MetalOne Guest

    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()
     
    MetalOne, Nov 17, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Welsh

    asyncore asynchat

    Michael Welsh, Jul 15, 2003, in forum: Python
    Replies:
    0
    Views:
    539
    Michael Welsh
    Jul 15, 2003
  2. Patrick Useldinger

    asynchat question

    Patrick Useldinger, Aug 17, 2003, in forum: Python
    Replies:
    1
    Views:
    389
    Patrick Useldinger
    Aug 17, 2003
  3. Joshua Moore-Oliva

    asyncore, asynchat and threads

    Joshua Moore-Oliva, Aug 4, 2004, in forum: Python
    Replies:
    4
    Views:
    1,095
    Joshua Moore-Oliva
    Aug 4, 2004
  4. Z. Kotzer
    Replies:
    0
    Views:
    364
    Z. Kotzer
    Mar 15, 2006
  5. David Hirschfield

    Help: asyncore/asynchat and terminator string

    David Hirschfield, Jan 16, 2007, in forum: Python
    Replies:
    0
    Views:
    342
    David Hirschfield
    Jan 16, 2007
Loading...

Share This Page