socket communication / callback

H

Hannes

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
 
B

Ben Morrow

Hannes said:
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
 
H

Hannes

Ben said:
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
 
B

Ben Morrow

Hannes said:
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
 
H

Hannes

Ben said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top