Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > socket communication / callback

Reply
Thread Tools

socket communication / callback

 
 
Hannes
Guest
Posts: n/a
 
      03-06-2004
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
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      03-06-2004

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]
 
Reply With Quote
 
 
 
 
Hannes
Guest
Posts: n/a
 
      03-07-2004
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
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      03-07-2004

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]
 
Reply With Quote
 
Hannes
Guest
Posts: n/a
 
      03-07-2004
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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57