Perl TCP Server respond with junk

Posted on 2004-11-16
Last Modified: 2013-11-29
Hello -

Having trouble with Perl TCP client/server socket.  Connects great, can pass string to server from client, but the return
from the server is junk or more specifially "IO::Socket::INET=GLOB(0x34b1638)"  Expecting "Got it text" from server print
statement.  What am I missing to get junk back rather than the intended text.  Many Thanks!!


use IO::Socket::INET;

my $port = "5001";
my $MaxConn = 5;

my $socket = IO::Socket::INET->new('LocalPort' => $port,
                           'Proto' => 'tcp',
                           'Listen' => $MaxConn,
                                   'Reuse' => 1)
    or die "Can't create socket ($!)\n";

print "\n(ddmmyyyyhhmm) Server listening\n";
while ($client = $socket->accept()) {

    while (<$client>) {
       (my $ClientAppId, my $ClientVersion, my $ClientAlias, my $ClientPassword) = split(/:/,$_);

     die "Can't fork: $!" unless defined (my $child = fork());
       if ($child == 0) {
        #close $client;
          print "From Client: $ClientAlias $ClientPassword\n";
          print $client 'Got it';
    close $client
      or die "Can't close ($!)\n";
die "Can't accept socket ($!)\n";

# client

use IO::Socket::INET;
use strict;

my $name = '';
my $port = 5001;

my $socket = IO::Socket::INET->new('PeerAddr' => $name,
                           'PeerPort' => $port,
                           'Proto' => 'tcp')
    or die "Can't create socket ($!)\n";

print "Client sending\n";
print $socket "hello test";
print "Socket Response: $socket\n";

close $socket
    or die "Can't close socket ($!)\n";

Question by:MarkAMac
    1 Comment
    LVL 1

    Accepted Solution

    Like this:
    $msg="This is the message";

    print "\nReceived message '", $text,"'\n";

    128 is the max message size.

    here ya go:

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Understanding FTPS File transfer is a common requirement in most Enterprises. While there are numerous ways to get a file from Point A to Point B over a network, perhaps the most common method still in use is FTP – File Transfer Protocol. FTP is …
    If your business is like most, chances are you still need to maintain a fax infrastructure for your staff. It’s hard to believe that a communication technology that was thriving in the mid-80s could still be an essential part of your team’s modern I…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now