Perl TCP Server respond with junk

Posted on 2004-11-16
Medium Priority
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 = 'webaddress.com';
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

Accepted Solution

pjargon earned 2000 total points
ID: 12596904
Like this:
$msg="This is the message";

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

128 is the max message size.

here ya go:  http://www.codetoad.com/perl_socket_programming.asp

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, the configuration steps in Zabbix to monitor devices via SNMP will be discussed with some real examples on Cisco Router/Switch, Catalyst Switch, NAS Synology device.
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

579 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