CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Win32::GUI/IO::Socket problems

 



some_random_kid
Novice

Jun 15, 2007, 9:59 PM

Post #1 of 4 (346 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:


Code
  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)


some_random_kid
Novice

Jun 17, 2007, 11:47 PM

Post #2 of 4 (335 views)
Re: [some_random_kid] Win32::GUI/IO::Socket problems [In reply to] Can't Post

Well, I still cant figure this out. But I didn't realize that because perl runs very fast when in multiple self contained programs, that I could of just created multiple servers (like one on port 2000 and one on port 2001). The first will fork the clients and recv, while the second will fork and send. Each "Client" will infact be two clients and the royal servers will share information using a text file(which will also log). I tested it and it's very fast because each program is small. I guess the main problem was that when the forked process used the same handle at the same time they freeze. So creating two clients instead of one created two entirely different handles. However, even having success, it's still not what I want, because now I have to deal with twice as much maintance and twice as much security. This will only be my temporary 1.0 client. I still would like help trying to make the single client version (1.1).


some_random_kid
Novice

Jun 18, 2007, 10:32 PM

Post #3 of 4 (325 views)
Re: [some_random_kid] Win32::GUI/IO::Socket problems [In reply to] Can't Post

Does anyone ever reply on this forum??????


KevinR
Veteran


Jun 19, 2007, 12:07 AM

Post #4 of 4 (323 views)
Re: [some_random_kid] Win32::GUI/IO::Socket problems [In reply to] Can't Post

I am about the only regular member of this forum that answers questions. But I have no clue how to answer your question. I suggest you try asking at www.perlmonks.com where there is a larger group of active and experienced perl coders.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives