Oh Monks!

I have a problem with unholy sockets - I can listen on port and connect to it from localhost, but from a remote host - I cannot. When I try the same port with netcat on listen mode - no problem, so the port is not blocked

The pseudo server code:

#!/usr/bin/perl -w use strict; use IO::Socket; use IO::Handle; use Fcntl qw(:DEFAULT); use POSIX qw(:errno_h); my $port = shift or return; my $sock = new IO::Socket::INET( LocalHost => 'localhost', LocalPort => $port, Proto => 'tcp', Listen => SOMAXCONN, Reuse => 1); $sock or die "could not create socket: $!"; #.......listening on port print "___accepting on port $port...\n"; my ($new_sock, $c_addr) = $sock->accept(); my ($client_port, $c_ip) =sockaddr_in($c_addr); my $client_ipnum = inet_ntoa($c_ip); my $client_host =gethostbyaddr($c_ip, AF_INET); print "got a connection from: $client_host [$client_ipnum] at port + $port\n"; close $sock; close $new_sock; exit;

When I try to connect I get:

telnet 212.31.100.100 20 Trying 212.31.100.100... telnet: connect to address 212.31.100.100: Connection refused telnet: Unable to connect to remote host

Any idea?


In reply to Unable to connect remotely by bucz

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.