socket recive problem

stefano cerbioni <[email protected]>
Newsgroups gmane.comp.lang.perl.beginners
Message-ID <CAAwR5B81nkBTwZkdrXnfhsjfLd9zRAH4E8=Q=yogQugcN2MixQ@mail.gmail.com>
hi i try to recive  a stream string  by  a client (write in C++) , if i use
netcat ,  work ok but  when i use a  script in perl work partially , recive
"Connection recieved from $name\n";,  but  $name is  blank , why ?? thanks
this is a script
use strict;
use Socket;

# use port 7890 as default
my $port = shift || 23456;
my $proto = getprotobyname('tcp');
my $server = "localhost";  # Host IP running the server

# create a socket, make it reusable
socket(SOCKET, PF_INET, SOCK_STREAM, $proto)
   or die "Can't open socket $!\n";
setsockopt(SOCKET, SOL_SOCKET, SO_REUSEADDR, 1)
   or die "Can't set socket option to SO_REUSEADDR $!\n";

# bind to a port, then listen
bind( SOCKET, pack_sockaddr_in($port, inet_aton($server)))
   or die "Can't bind to port $port! \n";

listen(SOCKET, 5) or die "listen: $!";
print "SERVER started on port $port\n";

# accepting a connection
my $client_addr;
while ($client_addr = accept(NEW_SOCKET, SOCKET)) {
   # send them a message, close connection
   my $name = gethostbyaddr($client_addr, AF_INET );
   print NEW_SOCKET "Smile from the server";
   print "Connection recieved from $name\n";
   close NEW_SOCKET;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.