sweetblood has asked for the wisdom of the Perl Monks concerning the following question:
Further more when I try the folowing code on another machine I get a 'Connection refused' error:#!/usr/bin/perl -w use strict; use IO::Socket; my $new_sock; my $buf; my $sock = new IO::Socket::INET (LocalHost => 'foo', localPort => 1880, Proto => 'tcp', Listen => 5, Reuse => 1 ); die "Unable to create socket: $!" unless $sock; print "Waiting for message...\n"; while ($new_sock = $sock->accept()) { print $buf while (defined ($buf = <$new_sock>)) } close ($sock);
These examples come from Advanced Perl, So I suspect they are correct.#!/usr/bin/perl -w use strict; use IO::Socket; my $sock = new IO::Socket::INET (PeerAddr => 'foo', PeerPort => 1880, Proto => 'tcp' ); die "Could not create socket: $!\n" unless $sock; while (1) { print "Enter message: "; chomp (my $msg = <STDIN>); print "Sending $msg\n"; print $sock "$msg\n"; $sock->flush; } close ($sock)
Update:
The server code is running on a windows nt4 machine while the client is an HPUX 11.x box
UPDATE:
I've got it working!
I noticed that while setting up the $sock object I did
The localHost shouldbe LocalHost.my $sock = new IO::Socket::INET (LocalHost => 'sgilbertdt', localPort => 1200, Proto => 'tcp', Listen => 5, Reuse => 1 );
As soon as I made the change and ran the script again, it showed up in netstat and I was able to pass the message from my Unix client.
Spelling Counts
Thanks Everyone
TIA
Sweetblood
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trouble with sockets
by eXile (Priest) on Jun 21, 2004 at 14:33 UTC | |
by sweetblood (Prior) on Jun 21, 2004 at 14:57 UTC | |
by eXile (Priest) on Jun 21, 2004 at 15:32 UTC | |
|
Re: Trouble with sockets
by pbeckingham (Parson) on Jun 21, 2004 at 14:29 UTC | |
by sweetblood (Prior) on Jun 21, 2004 at 14:49 UTC | |
by pbeckingham (Parson) on Jun 21, 2004 at 15:00 UTC | |
by tachyon (Chancellor) on Jun 22, 2004 at 05:01 UTC |