
some_random_kid
Novice
Jun 15, 2007, 9:59 PM
Post #1 of 4
(215 views)
|
|
Win32::GUI/IO::Socket problems
|
Can't Post
|
|
This has been very frustrating... I have been programming a Win32::GUI chat client and forking it to read/append and write at the same time. I was sure that it would work, however when I enter into a reading loop from the socket the entire program freezes up. I thought it might be a problem with fork, but when I subed it with a text file instead of a socket, it worked fine. This lead me to believe that it was a problem with the socket and the GUI, but something doesn't seem right, because when I don't fork and just send data through the socket there is no freezing. So what might be the problem? Here is a quick example script I made: use Win32::GUI; use IO::Socket; my $PORT = 2000; print "HOST: "; chomp(my $host = <STDIN>); print "\n"; my $window = Win32::GUI::Window -> new (-name => "Chat_Box", -text => "Chat Box", -width => 550, -height => 700, -left => 400, -top => 200); $window->AddTextfield( -name => "Message", -left => 85, -top => 69, -width => 300, -height => 140, -multiline=> 1); $window->AddButton( -name => "SendText", -text => "<<SEND>>", -left => 150, -top => 250, -width => 100, -height => 50); $window->AddTextfield( -name => "ViewChat", -left => 20, -top => 400, -width => 500, -height => 240, -multiline=> 1, -readonly => 1); my $client_socket = IO::Socket::INET -> new("$host:$PORT") or die "ERROR WITH CONNECTION\n"; system("CLS"); $window->ViewChat->Append("CONNECTED TO $host"); $window->Message->Append("Your Message Goes Here....."); start_chat(); sub start_chat { $pid = fork(); if($pid) { send_chat(); } else { recv_chat($client_socket); } } sub SendText_Click { my $some_text = $window->Message->Text(); print $client_socket "$some_text\n"; } sub send_chat { $window->Show(); Win32::GUI::Dialog(); } sub recv_chat { $socket = shift; while(1) { $data = <$socket>; if(defined($data)) { $window->ViewChat->Append("$data"); } } }
(This post was edited by some_random_kid on Jun 15, 2007, 10:05 PM)
|