http://qs321.pair.com?node_id=610425

kwaping has asked for the wisdom of the Perl Monks concerning the following question:

This is an interesting issue... I've written a small client program to connect to a certain port, send a query and receive back some information.
#!/usr/bin/perl use strict; use warnings; # usage: ./ltsp_client.pl mac_address use Carp; use IO::Socket::INET; die "Could not create socket: $!" unless my $sock = IO::Socket::INET->new( PeerAddr => 'xxxx.xxxx.com', PeerPort => xxxx, Proto => 'tcp', Type => SOCK_STREAM, Timeout => 10, ); foreach my $cmd (@ARGV) { print $sock "$cmd\n" or die $!; } print $sock "EOT\n" or die $!; my @text = <$sock>; close($sock) or die $!; print @text;
This script runs fine when I ssh to the LTSP server and run it from the command line. However, each LTSP terminal that will run this script takes its filesystem from the server, and the only writable directory is /tmp - the rest are read-only. When I try to run the script from the LTSP terminal's command line, I get the error "Could not create socket: Invalid argument at /usr/local/bin/ltsp_client.pl line 11."

Can anyone tell me why this is the case, and better yet how to resolve this issue? Thanks in advance!

Update: Resolved!! The issue lies somewhere in the hostname lookup. Changing the PeerAddr from using the name to using the IP resolved my issue. I still need to figure out why that's a problem, but at least now my project can progress. Thanks again to the responders, especially Thelonius for reminding me to use the debugger.

---
It's all fine and dandy until someone has to look at the code.

Replies are listed 'Best First'.
Re: IO::Socket::INET and LTSP read-only filesystem
by NetWallah (Canon) on Apr 17, 2007 at 03:17 UTC
    What OS, perl version and IO::Socket versions are you using ?
    There is useful disgnostic instruction, as well as proposed solutions at http://bugs.gentoo.org/show_bug.cgi?id=58122.
    "On some operating systems the Perl module IO::Socket reports obscure error
    on unsuccessful connect() in non-blocking mode as: "Invalid argument" in
    place of the true cause: "Connection refused". The remote service should be
    checked if available and accessible (firewall rules? network problems?).

    Another possible reason for "Invalid argument" reported by IO::Socket when
    running within chroot jail is some network-related system file missing in a
    chroot jail, e.g. /etc/protocols, /etc/services, /etc/netconfig,
    /etc/resolv.conf, /etc/nsswitch.conf, /etc/hosts, /etc/host.conf
    -- depending on the operating system in use. System debugging tools
    (debugger, strace, truss) may help to find the cause. "

         "Choose a job you like and you will never have to work a day of your life" - Confucius

      Thanks a lot for that helpful link and the information.

      OS: Linux 2.6.17.8.-ltsp-1
      perl -v: 5.8.0
      IO::Socket version: 1.26

      I'll talk to the sysadmin about getting Perl and IO::Socket updated, if possible.

      ---
      It's all fine and dandy until someone has to look at the code.
Re: IO::Socket::INET and LTSP read-only filesystem
by Thelonius (Priest) on Apr 17, 2007 at 01:51 UTC
    Well, of course, you've got xxxx for PeerPort!

    But, assuming you just put that there when you posted here :-) I have no idea. I think I would just perl -d and single step through it to see if you can pin down what's going on.

      /foreheadslap

      Thanks for reminding me of that! I'll give it a shot and report back.

      ---
      It's all fine and dandy until someone has to look at the code.
Re: IO::Socket::INET and LTSP read-only filesystem
by ikegami (Patriarch) on Apr 17, 2007 at 22:11 UTC
    By the way, specifying both Proto and Type is redundant. Take your pick. Either will do.
Re: IO::Socket::INET and LTSP read-only filesystem
by glenn (Scribe) on Oct 17, 2008 at 15:17 UTC
    I have written a test suite however now that i am trying to multithread the windows client (as it is used to establish multiple connections to test servers at the same time) all my data communications are failing to get back to the server. I think i have narrowed it down to the autoflush setting, any ideas? (it worked before multi-threading).

    Client (send):
    sub sendxml { #THREAD while (my $xml = $g_sendxmlQueue->dequeue) { my $xs = new XML::Simple(keeproot => 1, forcearray => 1); my $ref = $xs->XMLin($xml); #Send results to controller #my $ref = $_[0]; my $mhost = $ref->{job}->[0]->{controllerip}; my $mPort = 40000; dprint(2,"sendxml: sending xml data to host [$mhost:$mPort +]"); my $EC_SOCK = new IO::Socket::INET(PeerAddr => $mhost, PeerPort => $mPort, Proto => 'tcp'); if ($EC_SOCK) { dprint(1,"Network connection established to host [ +$mhost]"); $EC_SOCK->autoflush(1); unless ($ES_SOCK) { dprint(1,"autoflush setting killed connect +ion"); } my $xml = $xs->XMLout($ref); my @lines = split /\n/, $xml; foreach my $line (@lines) { print $EC_SOCK $line; } } if($ref->{job}->[0]->{jname} ne "discovery" && $re +f->{job}->[0]->{jname} ne "isalive") { print("Sent:\n-----\n$xml\n"); } close ($EC_SOCK); } else { print STDOUT "ERROR: Unable to connect to controll +er."; dprint(1,"ERROR: Unable to connect to controller." +); } } }
      i fixed it, either the issue was too many xml elements in a tag <job sessionid="" option100=""> or some new options (that i now delete just before sending) which contained '\\' (<job sysdirve="C:" workdir="c:\\temp\\work\\">)