Win32::GUI Text File not getting updated

Discussion in 'Perl Misc' started by steve, Sep 2, 2007.

  1. steve

    steve Guest

    Hi,
    I'm trying to learn a few things with the Win32::GUI side of things
    and sockets.
    I created a very simple receiver socket script and a sender script
    which work in as much that I can send different 'messages' between
    them :)

    Then I tried the same using a Win32::GUI setup, simple window with a
    textfield where the messages should appear as I send them, but nothing
    happens until I exit the window (with an Exit Button) at which point
    all the messages appear in the textfield.

    The applications is obviously stuck in some loop somewhere that is
    preventing the update of the textfield, but I cant figure it out :-(

    Here is my code for both send and receiver.....

    Sender##############################################################
    use IO::Socket;
    my $sock = new IO::Socket::INET (
    PeerAddr => 'localhost',
    PeerPort => '7070',
    Proto => 'tcp',
    );
    die "Could not create socket: $!\n" unless $sock;
    print "sending 1st...";
    print $sock "1,c:\\temp\\test.txt\n";
    sleep(5);
    print "sending 2nd...";
    print $sock "3,c:\\temp\\test_2.txt\n";
    sleep(5);
    print "sending 3rd...";
    print $sock "4";
    close($sock);

    Receiver##############################################################
    #!/usr/local/bin/perl -w

    use strict;
    use IO::Socket;
    use Switch;
    use warnings;
    use Win32::GUI;
    use Win32();
    use Win32::GUI::Loft::Design;

    eval {
    main();
    };
    sleep(10);

    Win32::GUI::MessageBox(0, "Error: $@", "hello Demo") if($@);

    sub main {
    my $fileWindow = "receiver.gld"; #You created this using
    The GUI Loft

    my $objDesign = Win32::GUI::Loft::Design->newLoad($fileWindow) or
    die("Could not open window file
    ($fileWindow)");

    $objDesign->buildWindow() or die("Could not build window
    ($fileWindow)");

    $Win32::GUI::Loft::window{Rx_Window}->Show();
    my $sock = new IO::Socket::INET (
    LocalHost => 'localhost',
    LocalPort => '7070',
    Proto => 'tcp',
    Listen => 1,
    Reuse => 1,
    );
    die "Could not create socket: $!\n" unless $sock;
    my $new_sock = $sock->accept();
    Win32::GUI::DoEvents();
    Win32::GUI::Dialog();

    while(<$new_sock>) {
    Win32::GUI::DoEvents();
    RxMsg($_);
    }
    close($sock);
    return(1);
    }

    sub RxMsg {
    my @actions = split(/,/);
    switch ($actions[0]) {
    case 1 {defined(my $win = $Win32::GUI::Loft::window{Rx_Window})
    or return(1);
    $win->RxTextfield->Append("action 1\r\n");
    chomp($actions[1]);
    $win->RxTextfield->Append("$actions[1]\r\n");
    open ACTION, "< $actions[1]" or die "cant open file : $!";
    while (my $line = <ACTION> ) {
    $win->RxTextfield->Append("$line\r\n");
    }
    }
    case 2 {defined(my $win =
    $Win32::GUI::Loft::window{Rx_Window}) or return(1);
    $win->RxTextfield->Append("action 2\r\n");
    }
    case 3 {defined(my $win =
    $Win32::GUI::Loft::window{Rx_Window}) or return(1);
    $win->RxTextfield->Append("action 3\r\n");
    chomp($actions[1]);
    $win->RxTextfield->Append("$actions[1]\r\n");
    open ACTION, "< $actions[1]" or die "cant open file : $!";
    while (my $line = <ACTION> ) {
    $win->RxTextfield->Append("$line\r\n");
    }
    }
    else {defined(my $win = $Win32::GUI::Loft::window{Rx_Window})
    or return(1);
    $win->RxTextfield->Append("action unknown\r\n");
    }
    }
    return(1);
    }

    sub ::ExitBtn_Click { defined(my $win =
    $Win32::GUI::Loft::window{Rx_Window}) or return(1);

    #Just exit
    return(-1);
    }
     
    steve, Sep 2, 2007
    #1
    1. Advertising

  2. steve

    Robert May Guest

    On Sep 2, 7:24 am, steve <> wrote:

    > I created a very simple receiver socket script and a sender script
    > which work in as much that I can send different 'messages' between
    > them :)
    >
    > Then I tried the same using a Win32::GUI setup, simple window with a
    > textfield where the messages should appear as I send them, but nothing
    > happens until I exit the window (with an Exit Button) at which point
    > all the messages appear in the textfield.
    >
    > The applications is obviously stuck in some loop somewhere that is
    > preventing the update of the textfield, but I cant figure it out :-(


    [snip code]

    > Win32::GUI::Dialog();


    Try removing that line from your receiver - it won't return until you
    close your window. Win32::GUI::DoEvents() is the 'non-blocking'
    equivalent.

    Regards,
    Rob.
     
    Robert May, Sep 2, 2007
    #2
    1. Advertising

  3. steve

    steve Guest

    On Sep 2, 10:41 am, Robert May <> wrote:
    > On Sep 2, 7:24 am, steve <> wrote:
    >
    > > I created a very simple receiver socket script and a sender script
    > > which work in as much that I can send different 'messages' between
    > > them :)

    >
    > > Then I tried the same using a Win32::GUI setup, simple window with a
    > > textfield where the messages should appear as I send them, but nothing
    > > happens until I exit the window (with an Exit Button) at which point
    > > all the messages appear in the textfield.

    >
    > > The applications is obviously stuck in some loop somewhere that is
    > > preventing the update of the textfield, but I cant figure it out :-(

    >
    > [snip code]
    >
    > > Win32::GUI::Dialog();

    >
    > Try removing that line from your receiver - it won't return until you
    > close your window. Win32::GUI::DoEvents() is the 'non-blocking'
    > equivalent.
    >
    > Regards,
    > Rob.


    Many Thanks Rob,
    works an treat now

    regards
    Steve
     
    steve, Sep 4, 2007
    #3
    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. John Rose
    Replies:
    4
    Views:
    6,581
    John Rose
    Dec 24, 2003
  2. =?Utf-8?B?bm93YW5kZXZlcjI5?=

    Unbound fields not getting updated, written to DB VS.Net 2003

    =?Utf-8?B?bm93YW5kZXZlcjI5?=, Apr 6, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    401
    =?Utf-8?B?bm93YW5kZXZlcjI5?=
    Apr 6, 2006
  3. Gensek

    Grid not getting updated

    Gensek, Mar 3, 2005, in forum: Python
    Replies:
    0
    Views:
    275
    Gensek
    Mar 3, 2005
  4. Dmitry Korolyov

    Datagrid not updated during delete, but updated during insert and update

    Dmitry Korolyov, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    416
    Dmitry Korolyov
    Sep 22, 2003
  5. Replies:
    19
    Views:
    245
    Andreas Perstinger
    Oct 7, 2013
Loading...

Share This Page