in reply to poe/win32/fork/threads chat-application

If you want a simple GUI on Windows, I suggest Tk. Tk contains an "event-loop" so it can be used like POE. Here is a Tk client-server example. Start the server, then as many clients as you want. If you notice, there is a a separate entry box at the bottom of the client, so you can receive and send simultaneously. There are many, many variations on this type of example. The big distinction ( as you will learn as you delve into sockets) is that IO::Select uses a blocking mode. That is, for short messages it is fine, but if you transfer huge files, it will block others until the file transfer is complete. In those cases you want a forking or threaded server. Search for examples of them. For instance Sockets-File-Upload with Net::EasyTCP which uses the very handy Net::EasyTCP module.

# server #!/usr/bin/perl -w use strict; use IO::Select; use IO::Socket; $| = 1; # create the socket #my $host = shift || 'localhost'; #my $host = '192.168.0.1'; my $host = 'localhost'; my $port = 12345; my $socket = IO::Socket::INET->new( LocalPort => $port, LocalAddr => $host, Listen => 5, Proto => 'tcp', Reuse => 1, ); defined $socket or die "ERROR: Can't create socket: $!\n"; print STDERR "Socket open ... listening for incoming calls ..\n"; my $select = IO::Select->new($socket); my %socks; while (1) { foreach my $fh ($select->can_read) { if ($fh == $socket) { # new connection my $new = $socket->accept; $select->add($new); $socks{$new}{FH} = $new; print STDERR "Received new connection ($new) ..\n"; } else { my $data = <$fh>; if (defined $data) { $data =~ tr/\r\n//d; foreach my $handle (keys %socks) { print {$socks{$handle}{FH}} "$handle $data\n"; } } else { print "BYE $fh.\n"; $select->remove($fh); delete $socks{$fh}; $fh->close; } } } } #### end server #######
# client #!/usr/bin/perl use warnings; use strict; use Tk; #use IO::Select; use IO::Socket; require Tk::ROText; # create the socket my $host = shift || 'localhost'; my $port = 12345; my $socket = IO::Socket::INET->new( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', ); defined $socket or die "ERROR: Can't connect to port $port on $host: $ +!\n"; print STDERR "Connected to server ...\n"; my $mw = new MainWindow; my $log = $mw->Scrolled(qw/ROText -scrollbars ose/)->pack; my $txt = $mw->Entry()->pack(qw/-fill x -pady 5/); $mw ->bind('<Any-Enter>' => sub { $txt->Tk::focus }); $txt->bind('<Return>' => [\&broadcast, $socket]); $mw ->fileevent($socket, readable => sub { my $line = <$socket>; unless (defined $line) { $mw->fileevent($socket => readable => ''); return; } $log->insert(end => $line); }); MainLoop; sub broadcast { my ($ent, $sock) = @_; my $text = $ent->get; $ent->delete(qw/0 end/); print $sock $text, "\n"; }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum