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

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

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

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. Kathryn Bean
    Replies:
    2
    Views:
    11,613
    Alex Kizub
    Oct 13, 2004
  2. James Willans
    Replies:
    0
    Views:
    416
    James Willans
    Dec 19, 2004
  3. Tom Dyess
    Replies:
    10
    Views:
    1,406
    Esmond Pitt
    Jan 13, 2005
  4. Andrew Thompson

    OutOfMemoryError with socket communication

    Andrew Thompson, Aug 16, 2005, in forum: Java
    Replies:
    13
    Views:
    992
    Thomas Hawtin
    Aug 18, 2005
  5. Mike
    Replies:
    1
    Views:
    367
    Gandalf
    Jun 1, 2004
  6. DaTurk
    Replies:
    1
    Views:
    401
    Erik Wikström
    Aug 26, 2008
  7. Laszlo Nagy
    Replies:
    1
    Views:
    7,244
    Mark Wooding
    Jan 27, 2009
  8. Steve Holden
    Replies:
    1
    Views:
    1,006
Loading...