Rudolf has asked for the wisdom of the Perl Monks concerning the following question:
Hello! any help and tips on better code would be appreciated :), my question spawns from the code below... It works just how I would like it to on Windows 7, and also on Backtrack (without the system commands and win32 module ofc). However my server just wont seem to work on Windows XP for some reason, as far as I know it opens the socket successfully. When my client ( on another computer ) attempts to send a message that the server should get, my client says it can not connect. I have tried using different ports and such to no avail. I should note I am new to network programming alltogeather; Thank you! (CLIENT code below server)
And this is the subroutine I call in another program on another computer:system("color 07"); use Win32::Console; my $CONSOLE = Win32::Console->new(STD_OUTPUT_HANDLE); my $attr = $CONSOLE->Attr(); # Get current console colors use IO::Socket; $| = 1; ########################################################### $socket = new IO::Socket::INET ( LocalPort => '4444', Proto => 'tcp', Listen => 1, Reuse => 1 ); die "Coudn't open socket" unless $socket; while(1){ if($client = $socket->accept()){ while(<$client>){ chomp; my $line = $_; my @chars = split(//,$line); foreach(@chars){ if($_ eq '[' || $_ eq ']'){ $CONSOLE->Attr($FG_LIGHTRED); print $_; $CONSOLE->Attr($attr); } elsif($_ eq '{' || $_ eq '}'){ $CONSOLE->Attr($FG_MAGENTA); print $_; $CONSOLE->Attr($attr); } else{ print $_; } } print "\n"; } } }
sub global_send($){ my $data = $_[0]; foreach my $ip(@connected_ips){ my $server = new IO::Socket::INET ( PeerAddr => $ip, PeerPort => 4444, Proto => 'tcp', ) or warn "Can not connect to client: $ip\nSysErr: $!\n"; if(!defined($server)){return;} $server->send($data); $server->close(); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: server with IO::Socket::INET
by BrowserUk (Patriarch) on Mar 11, 2012 at 18:22 UTC | |
by Rudolf (Pilgrim) on Mar 11, 2012 at 18:30 UTC | |
by BrowserUk (Patriarch) on Mar 11, 2012 at 18:35 UTC | |
by Rudolf (Pilgrim) on Mar 11, 2012 at 18:40 UTC | |
by BrowserUk (Patriarch) on Mar 11, 2012 at 21:09 UTC | |
| |
|
Re: server with IO::Socket::INET
by tobyink (Canon) on Mar 11, 2012 at 19:57 UTC | |
|
Re: server with IO::Socket::INET
by Rudolf (Pilgrim) on Mar 11, 2012 at 21:45 UTC | |
|
Re: server with IO::Socket::INET
by Rudolf (Pilgrim) on Mar 11, 2012 at 18:45 UTC | |
|
Re: server with IO::Socket::INET
by Rudolf (Pilgrim) on Mar 11, 2012 at 19:08 UTC | |
|
Re: server with IO::Socket::INET
by Rudolf (Pilgrim) on Mar 11, 2012 at 21:10 UTC |