I'm having some trouble getting my first foray into socket programming to work. This, I expect should open a socket on host 'foo' port 1880. This seems to work except, when I do a 'netstat -a' I don't see an entry for port 1880 which I expect to see listening. Here is the code:
#!/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);
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 $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)
These examples come from Advanced Perl, So I suspect they are correct.
Any suggestions will be greatly appreciated!

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

my $sock = new IO::Socket::INET (LocalHost => 'sgilbertdt', localPort => 1200, Proto => 'tcp', Listen => 5, Reuse => 1 );
The localHost shouldbe LocalHost.

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


In reply to Trouble with sockets by sweetblood

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.