cta has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone,

I really need your help about a problem that I'm having here.
My program supposes to wait permanently for an event that comes from other machine and integrates it to my Tk Canvas. Apparently 2 issues appear :

1. First of all, the event is represented by a Perl data structure. So, in order to send it to other machine, it has to be translated to another format. The solution that I think of is using JSON format.
Do you know any better way to do that ?

2. Second of all, I have to integrate that incoming event in real time to my GUI and I don't know how to do it yet. There is a command called fileevent solve that problem but It works only on Unix.
Any suggestion for this problem would help me alot.

Thanks in advance.
Christina--

Replies are listed 'Best First'.
Re: solution for fileevent on Win32 ???
by pc88mxer (Vicar) on Jul 10, 2008 at 17:03 UTC
    This exact issue is discussed in the section "Polling Win32 Sockets" of the book "Mastering Perl/Tk: Graphical User Interfaces in Perl".

    The basic idea is to set up a timer event to poll the socket.

    As for other serialization formats, you might consider YAML or Storable.

      thanks for your promptly responses.
      I did try to use the timer event but I don't see which method you can use to send data through the socket at the sender part.

      When you call the can_read method, can you get the event data or just the boolean value saying if there is any available data at the socket?
        A socket is just a file handle, so you can use syswrite or print.

        can_read (from IO::Select) only returns true or false. It is telling you that you will not block if you try to read from the file handle. You have to call read or sysread to get the data.

Re: solution for fileevent on Win32 ???
by zentara (Cardinal) on Jul 10, 2008 at 19:29 UTC
    See Non-blocking socket read on Windows. I "think" that fileevent will work on Win32, did you try it? The problem with fileevent on Win32, is that it won't work on pipe filehandles( you need the Win32::Pipe module). But it should works on sockets. IPC::Run(which uses sockets)is often suggested as an IPC substitute for IPC::Open3 (which uses pipes), for use on Win32.

    Here is an example, see if it runs for you on Win32. Tk Realtime data aquisition


    I'm not really a human, but I play one on earth CandyGram for Mongo
      I tried using fileevent command and it didn't work on Win32 and you were right about the handle. Thanks.
      I'm still working on the timer event to see if I could get around the problem. And hmm having error while trying to open the socket.
Re: solution for fileevent on Win32 ???
by jethro (Monsignor) on Jul 10, 2008 at 16:44 UTC
    2. You could make a timer event that checks for that incoming event. Depends on how real time your real time constraint really is.

    Second possibility could be to find an X event that could be hijacked to signify your event, but that sounds to me a bit like a hack.