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 781485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:14:13+00:00 2026-05-14T20:14:13+00:00

In sockets I have written the client server program. First I tried to send

  • 0

In sockets I have written the client server program. First I tried to send the normal string among them it sends fine. After that I tried to send the hash and array values from client to server and server to client. When I print the values using Dumper, it gives me only the reference value. What should I do to get the actual values in client server?

Server Program:

use IO::Socket;
use strict;
use warnings;

my %hash = ( "name" => "pavunkumar " , "age" => 20 ) ;
my $new  = \%hash ;
#Turn on System variable for Buffering output
$| = 1;
# Creating a a new socket
my $socket=
IO::Socket::INET->new(LocalPort=>5000,Proto=>'tcp',Localhost =>
        'localhost','Listen' => 5 , 'Reuse' => 1 );
die "could not create $! \n" unless ( $socket );
        print "\nUDPServer Waiting port 5000\n";
        my $new_sock =  $socket->accept();
        my $host =  $new_sock->peerhost();
        while(<$new_sock>)
        {
        #my $line = <$new_sock>;
        print Dumper "$host $_";
        print $new_sock $new . "\n";
        }
        print "$host is closed \n" ;

Client Program

use IO::Socket;                               
use Data::Dumper ;                            
use warnings ;                                
use strict ;                                  

my %hash  = ( "file" =>"log.txt" , size => "1000kb") ;

my $ref = \%hash ;


# This client for connecting the specified below address and port 
# INET function will create the socket file and establish the connection with
# server

my $port = shift || 5000 ;
my $host = shift || 'localhost';
my $recv_data ;
my $send_data;
my $socket = new IO::Socket::INET (
                                  PeerAddr  => $host ,
                                  PeerPort  => $port ,
                                  Proto => 'tcp', )

or die "Couldn't connect to Server\n";
while (1)
{
        my $line = <stdin> ;
        print $socket $ref."\n";
        if ( $line = <$socket> )
        {
                print Dumper  $line ;
        }
        else
        {
                print "Server is closed \n";
                last ;
        }

}

I have given my sample program about what I am doing. Can any one tell me what I am doing
wrong in this code? And what I need to do for accessing the hash values?

  • 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-05-14T20:14:13+00:00Added an answer on May 14, 2026 at 8:14 pm

    When you say

    print $ref;
    

    , you’re in part instructing Perl to turn $ref into a string (since only strings can be printed). It turns out that references don’t turn into very useful strings by default.

    You need to turn $ref into a string that you can send across the wire and then decode on the other side to get the data back out. This process is referred to as “serialization”. Data::Dumper‘s output is actually a valid serialization of its arguments, but the basic serialization module in Perl is Storable.

    Procedurally, you can say[1]

    use Storable qw(nfreeze); # nfreeze rather than freeze because
                              # we want a network-portable string
    ...
    print nfreeze($ref);
    

    on one side and

    use Storable qw(thaw);
    ...
    my $ref = thaw($line);
    

    on the other.

    There’s also an OO interface; read the Storable documentation for more information.

    [1]: Notice the yaddayaddas. This is incomplete code that merely illustrates the key differences from your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 409k
  • Answers 409k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The following hack may help you achieve your goal. It's… May 15, 2026 at 7:06 am
  • Editorial Team
    Editorial Team added an answer 1000 is a very small number. Also, keep in mind… May 15, 2026 at 7:06 am
  • Editorial Team
    Editorial Team added an answer If you are using basic authentication this will not be… May 15, 2026 at 7:06 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.