Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Tcp client and servers

by ant (Scribe)
on Sep 27, 2000 at 18:13 UTC ( #34199=perlquestion: print w/replies, xml ) Need Help??

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

Hi
I have created two programs, one a server whick works correctly and a client program which when executed fails
and returns the error Illegal seek. Why? What does this mean? here is the code for client.

#!/opt/bin/perl
#print "Content-type: text/html\n\n";
use IO::Socket;
use Sys::Hostname;
$hostname = hostname();
print "hostname is $hostname \n";
$sock = new IO::Socket::INET (PeerAddr =>'$hostname',
PeerPort => 3334,
Proto => 'tcp'
);
die "Socket could not be created reason: $!\n " unless $sock;
foreach (1..10){
print $sock "Msg $_ : How are you? \n";
$sock->flush();
}
close ($sock);

Any help would be gratefully accepted.
Thanks
Ant

Replies are listed 'Best First'.
Re: Tcp client and servers
by merlyn (Sage) on Sep 27, 2000 at 19:16 UTC
    Graham Barr didn't seem to understand that errors for "system-related" operations should be returned by setting $! to something sane, and instead put the error text in $@, which is reserved for eval errors. No amount of pleading with him has seemed to convince him that he needs to set the appropriate value.

    So try looking in $@ instead of $! when you get an IO::Socket::mumble error.

    -- Randal L. Schwartz, Perl hacker

      Thanks for your reply
      I solved the problem eventually. I had hardcoded the computer name address in the server program and used the hostname() method
      in the client program. Even though both programs sat on the same computer, the client could not figure out where to
      send the data to.
      All this became a little clearer when I put in the -w switch in at the top. But i have now inserted $@ instead of $i in the code.
      many thanks
      Ant

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://34199]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2023-02-06 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (33 votes). Check out past polls.

    Notices?