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)

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(); } }

Replies are listed 'Best First'.
Re: server with IO::Socket::INET
by BrowserUk (Patriarch) on Mar 11, 2012 at 18:22 UTC

    Maybe you could show us the "client" code?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Updated my post, now includes client code

        And the full error text (cut&paste). Preferably add $^E to it first.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Re: server with IO::Socket::INET
by tobyink (Canon) on Mar 11, 2012 at 19:57 UTC

    Are there any firewalls getting in the way? Obvious problem, but easy to forget to check.

Re: server with IO::Socket::INET
by Rudolf (Pilgrim) on Mar 11, 2012 at 21:45 UTC

    Well, it was the dang firewall :/ I just have to figure out a way to let my program through it or prompt windows to ask the user... thanks for your help :) -Rudolf

Re: server with IO::Socket::INET
by Rudolf (Pilgrim) on Mar 11, 2012 at 18:45 UTC

    Can not connect to client: 192.168.1.67 SysErr: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connec ted host has failed to respond.

Re: server with IO::Socket::INET
by Rudolf (Pilgrim) on Mar 11, 2012 at 19:08 UTC
    $^E returned this : "The handle is invalid"
Re: server with IO::Socket::INET
by Rudolf (Pilgrim) on Mar 11, 2012 at 21:10 UTC

    hmm, good question about the firewall, honestly Im not sure. Windows 7 *DID* prompt me to allow the client to communicate to the server before I could use it. Windows XP has not, will look into this.