#usr/bin/perl use strict; use warnings; use IO::Socket; $| = 1; my $client; my $socket= new IO::Socket::INET( PerHost => '192.168.0.34', PeerPort => '4500', Proto => 'tcp', ); die "Couln't open socket: $!" unless $socket; #open ALERT, ">alerts" or die " Unable to open file alerts \n"; while(1) { print "Accepting Socket....\n"; $client = $socket->accept(); print "Socket Accepted:$client....\n"; my $addr = $client->peerhost(); my $port = $client->peerport(); print "Got Connection from \"$addr\" at port $port\n"; while(1) { $client->recv(my $rec,1024); my $date = `date`; # print ALERT "[ $date ] :$rec\n"; print "[ $date ] :$rec\n"; } }
When I try to run this script I'm getting this output...
Accepting Socket.... Use of uninitialized value in concatenation (.) or string at servertes +t.pl line 18. Socket Accepted:.... Can't call method "peerhost" on an undefined value at servertest.pl li +ne 19.
FYI
[root@station34 Socket]# telnet 192.168.0.34 4500 Trying 192.168.0.34... Connected to station34 (192.168.0.34). Escape character is '^]'. ^] telnet> quit Connection closed.
Am I missing something here?

In reply to Problem with Socket Programming Perl Script by ashok.g

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.