socket communication / callback

Discussion in 'Perl Misc' started by Hannes, Mar 6, 2004.

  1. Hannes

    Hannes Guest

    Hi,

    I'm wondering if it's possible to use sockets for the folloing purpose:
    A running process acts as a kind of server, sometimes it receives some data.
    The receiving should trigger some functions (some display update based on
    the new values received). While waiting, the process should be responsive
    to local user-interactions.

    I'm new to networking/socket programming and don't know how to implement
    this in a way that the receiving of data triggers some sort of callback and
    waiting for the receiving of the data without beeing "locked"


    Hannes
     
    Hannes, Mar 6, 2004
    #1
    1. Advertising

  2. Hannes

    Ben Morrow Guest

    Hannes <> wrote:
    > I'm wondering if it's possible to use sockets for the folloing purpose:
    > A running process acts as a kind of server, sometimes it receives some data.
    > The receiving should trigger some functions (some display update based on
    > the new values received). While waiting, the process should be responsive
    > to local user-interactions.
    >
    > I'm new to networking/socket programming and don't know how to implement
    > this in a way that the receiving of data triggers some sort of callback and
    > waiting for the receiving of the data without beeing "locked"


    The best way is to put the sockets into non-blocking mode and use an
    event loop. If you are doing the display using Tk or Gtk then these
    toolkits provide an event loop already; if not then there are systems on
    CPAN such as POE and stem that provide pre-packaged event loops which
    you may find helpful.

    Ben

    --
    It will be seen that the Erwhonians are a meek and long-suffering people,
    easily led by the nose, and quick to offer up common sense at the shrine of
    logic, when a philosopher convinces them that their institutions are not based
    on the strictest morality. [Samuel Butler, paraphrased]
     
    Ben Morrow, Mar 6, 2004
    #2
    1. Advertising

  3. Hannes

    Hannes Guest

    Ben Morrow wrote:

    >
    > Hannes <> wrote:
    >> I'm wondering if it's possible to use sockets for the folloing purpose:
    >> A running process acts as a kind of server, sometimes it receives some
    >> data. The receiving should trigger some functions (some display update
    >> based on the new values received). While waiting, the process should be
    >> responsive to local user-interactions.
    >>
    >> I'm new to networking/socket programming and don't know how to implement
    >> this in a way that the receiving of data triggers some sort of callback
    >> and waiting for the receiving of the data without beeing "locked"

    >
    > The best way is to put the sockets into non-blocking mode and use an
    > event loop. If you are doing the display using Tk or Gtk then these
    > toolkits provide an event loop already; if not then there are systems on
    > CPAN such as POE and stem that provide pre-packaged event loops which
    > you may find helpful.
    >
    > Ben
    >



    Hi,

    thanks.
    Because I'm new to sockets I didn't really know about the non-blocking
    mode...
    Yes, I'm using perl/Tk. How would you use an event loop? Idle-Callback
    polling? Or is there a way to get a callback on incoming data (asynchronous
    notification - like in C via SIGIO...?)

    Hannes
     
    Hannes, Mar 7, 2004
    #3
  4. Hannes

    Ben Morrow Guest

    Hannes <> wrote:
    > Ben Morrow wrote:
    > > Hannes <> wrote:
    > >>
    > >> I'm wondering if it's possible to use sockets for the folloing purpose:
    > >> A running process acts as a kind of server, sometimes it receives some
    > >> data. The receiving should trigger some functions (some display update
    > >> based on the new values received). While waiting, the process should be
    > >> responsive to local user-interactions.

    > >
    > > The best way is to put the sockets into non-blocking mode and use an
    > > event loop. If you are doing the display using Tk or Gtk then these
    > > toolkits provide an event loop already; if not then there are systems on
    > > CPAN such as POE and stem that provide pre-packaged event loops which
    > > you may find helpful.

    >
    > Because I'm new to sockets I didn't really know about the non-blocking
    > mode...
    > Yes, I'm using perl/Tk. How would you use an event loop? Idle-Callback
    > polling? Or is there a way to get a callback on incoming data (asynchronous
    > notification - like in C via SIGIO...?)


    See perldoc Tk::fileevent.

    Ben

    --
    Every twenty-four hours about 34k children die from the effects of poverty.
    Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
    that image, that ghastly, grey-billowing, double-barrelled fall, repeated
    twelve times every day. Full of children. [Iain Banks]
     
    Ben Morrow, Mar 7, 2004
    #4
  5. Hannes

    Hannes Guest

    Ben Morrow wrote:

    >
    > Hannes <> wrote:
    >> Ben Morrow wrote:
    >> > Hannes <> wrote:
    >> >>
    >> >> I'm wondering if it's possible to use sockets for the folloing
    >> >> purpose: A running process acts as a kind of server, sometimes it
    >> >> receives some data. The receiving should trigger some functions (some
    >> >> display update based on the new values received). While waiting, the
    >> >> process should be responsive to local user-interactions.
    >> >
    >> > The best way is to put the sockets into non-blocking mode and use an
    >> > event loop. If you are doing the display using Tk or Gtk then these
    >> > toolkits provide an event loop already; if not then there are systems
    >> > on CPAN such as POE and stem that provide pre-packaged event loops
    >> > which you may find helpful.

    >>
    >> Because I'm new to sockets I didn't really know about the non-blocking
    >> mode...
    >> Yes, I'm using perl/Tk. How would you use an event loop? Idle-Callback
    >> polling? Or is there a way to get a callback on incoming data
    >> (asynchronous notification - like in C via SIGIO...?)

    >
    > See perldoc Tk::fileevent.
    >
    > Ben
    >


    Of cause! That can be used for the socket-equivalent of an filehandle..
    Didn't think that far... ;-)

    Thanks for your help
     
    Hannes, Mar 7, 2004
    #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. Laszlo Nagy
    Replies:
    1
    Views:
    5,122
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    1,034
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    601
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Replies:
    0
    Views:
    717
    Steve Holden
    Feb 1, 2009
  5. Steve Holden
    Replies:
    1
    Views:
    762
Loading...

Share This Page