Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7708917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:44:02+00:00 2026-06-01T00:44:02+00:00

Here is a sample that fails: #!/usr/bin/perl -w # client.pl #—————- use strict; use

  • 0

Here is a sample that fails:

#!/usr/bin/perl -w
# client.pl
#----------------

use strict;
use Socket;

# initialize host and port
my $host = shift || 'localhost';
my $port = shift || 55555;
my $server = "10.126.142.22";

# create the socket, connect to the port
socket(SOCKET,PF_INET,SOCK_STREAM,(getprotobyname('tcp'))[2])
   or die "Can't create a socket $!\n";
connect( SOCKET, pack( 'Sn4x8', AF_INET, $port, $server ))
       or die "Can't connect to port $port! \n";

my $line;
while ($line = <SOCKET>) {
    print "$line\n";
}
close SOCKET or die "close: $!";

with the error:

Argument "10.126.142.22" isn't numeric in pack at D:\send.pl line 16.
Can't connect to port 55555!

I am using this version of Perl:

This is perl, v5.10.1 built for MSWin32-x86-multi-thread
(with 2 registered patches, see perl -V for more detail)

Copyright 1987-2009, Larry Wall

Binary build 1006 [291086] provided by ActiveState http://www.ActiveState.com
Built Aug 24 2009 13:48:26

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

While I am running the netcat command on the server side. Telnet does work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:44:03+00:00Added an answer on June 1, 2026 at 12:44 am

    The problem is that the pack template Sn4x8 is in error — and shouldn’t be used in the first place. Something like pack_sockaddr_in($port, inet_aton($server)) as documented in Socket would be more likely to work.

    But ideally, you wouldn’t use the low-level Socket code at all. Here’s a nicer bit of code that does it using IO::Socket, which is also a core part of perl for the past 15 years:

    use strict;
    use IO::Socket::INET;
    
    my $host = shift || 'localhost'; # What is this here for? It's not used
    my $port = shift || 55555;
    my $server = "10.126.142.22";
    
    my $socket = IO::Socket::INET->new(
            PeerAddr => $server,
            PeerPort => $port,
            Proto => 'tcp',
    ) or die "Can't connect to $server: $@";
    
    while (my $line = <$socket>) {
            print $line; # No need to add \n, it will already have one
    }
    
    close $socket or die "Close: $!";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a sample fiddle: http://jsfiddle.net/K2zyU/4/ The problem I am experiencing is that the
Sample: I've created a minimal set of files that highlight the issue here: http://uploads.omega.org.uk/Foo3.zip
I guess that I am missing something here. After having found this sample within
I'm writing a simple mail client in Perl, that uses SMTP to log in
I got some sample code from the net here: http://www.javadb.com/sending-a-post-request-with-parameters-from-a-java-class That works fine. It
Here is a simple function that converts a string to an integer. int str2int(char
Here is a simple code that shows what I think is a bug when
I have simple algorithm that clean the whitespace from half string until end. Here
Web-development novice here. I want to try implementing a simple web site that uses
i'm missing something fundamental here. i have a very simple custom class that draws

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.