develooper Front page | perl.beginners | Postings from January 2002

Re: Access Transmitted Data On "Server" Side Of A TCP Socket

Thread Previous
From:
Dave Benware
Date:
January 31, 2002 11:40
Subject:
Re: Access Transmitted Data On "Server" Side Of A TCP Socket
Message ID:
3C599D9A.EAF58AF8@Townisp.com


Hewlett Pickens wrote:
> 
> Using O'Reilly's "Learning Perl", have set up a "bare bones" socket
> connection between two computers to send a small amount of data from the
> "client" to the "server".  (For learning, not for the real world.)
> 
> The client sends "are you there" and the server responds with "I am here,
> what do you want".
> 
> Each side prints the data it receives.
> 
> The client correctly displays the received:  "I am here ..."
> 
> The server displays junk for the data its received, meaning I haven't
> correctly acquired it.
> 
> Code snippets from the server and client are in the text attachment.  I'd
> appreciate it if someone could point out the error I'm making in the server
> code.
> 
> Thanks,
> 
> Hew

I've been thru this, but it was months and months ago and
I'm heading out for work, but I'll take a quick stab at it.

I think you should see what is in $client before you do anything
else.  So try adding this one line...

while ($client = $server->accept())
 {
    print "$client\n";  #ADD THIS JUST FOR KICKS, SEE WHAT YAH GET
    $client->autoflush(1);
    print "HEWSRV004 - I have a connection from $client \n";
    $bufferSize = 100;
       # the "->recv" was not in Learning Perl page 441.  Got
       # it from reading doc for IO::Socket
    $dataIn = $client->recv($bufferIn, $bufferSize);
    print "HEWSRV005 - I received this data: $dataIn \n";
    print $client "I am here. What do you want \n";
    print "HEWSRV999 - Data was sent to client\n\n";
 }

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About