Good afternoon,
I have been playing around with perl sockets (IO::Sockets) but have been experiencing some unexplained problems. I replicated the code from:
http://www.perlfect.com/articles/sockets.shtml
and have looked through the documentation about the sockets module at:
http://search.cpan.org/author/GBARR/IO-1.20/IO/Socket.pm
The below is my implimetation of the code from the first web site:
This first bit if code is the sending portion of the socket (cliant)
#!/usr/bin/perl use strict; use IO::Socket; my $sock = new IO::Socket::INET ( PeerAddr => '10.2.7.193', PeerPort => '7788', Proto => 'tcp', ); die "Could not create socket :-( $!\n" unless $sock; print $sock "hello world!"; close($sock);
The next bit of code is the recieving portion of the socket code (server)
#!/usr/bin/perl -w use strict; use IO::Socket; my $sock = new IO::Socket::INET ( LocalHost => '10.2.7.193', LocalPort => '7788', Proto => 'tcp', Listen => 2, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; my $new_sock = $sock->accept(); while(defined(<$new_sock>)) { my $storage = $_; print $storage; } close($sock);
When I execute the recieving program on the server machine and then execute the sending program on the cliant machine, I would expect that the cliant would send the text "hello world" to the server machine. I, however, am recieving the following error message instead:
Use of uninitialized value in print at ./socket_serv line 17, <GEN1> l +ine 1.
I am new to socket programming, but do realize that is very powerful. If anyone has any ideas of what might be wrong or any resources that might help me out, I would be very appreciative of your help. Thank you for your time in looking at my problem. Have a nice day :-)

In reply to Perl Sockets Problem by JoeJaz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.