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)
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";
}
}
}
And this is the subroutine I call in another program on another computer:
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();
}
}