Thanks for the reply. Anyways here is my client side code.

#!/usr/bin/perl use strict; use warnings; use IO::Socket; use IO::Select; use IO::Socket::INET; use Thread; my @handles; my @activePorts; my @events; sub PortConn { my ($port)=@_; print " Trying to connect to port $port .... \n"; my $rethandle ; my $retryCount=0; LOOP: until ($rethandle = new IO::Socket::INET (PeerAddr => 'x. +x.x.x', PeerPort => $port, Proto => 'tcp', )){ sleep 1; # changed ip to x.x.x.x last LOOP if (++$retryCount > 10); # If not able to connect in + 10 seconds then break out of loop } if ($retryCount > 10) { # Cannot connect to port since retryCount + is greater than 0. Therefore putting in bad file print "Could not connect to port $port \n"; open FILE, ">> ./badFile" or die "Error: $!"; print FILE "$port \n"; close(FILE); return; } else { # Connected to specified port therefore putting file handl +e and port in good file $rethandle->autoflush(1); print("Connected to port $port \n"); open FILE, ">> ./goodFile" or die "Error: $!"; # open file for + append, die otherwise print FILE "$rethandle $port \n"; close(FILE); return; } } ###################################################################### +#### # Function to store all the active ports and handles from goodFile fil +e # # into appropriate arrays for active ports and handles + # ###################################################################### +#### sub ActivePortsAndHandles { if (-s "goodFile") { # Check if file exist and is non-zero size splice(@handles); # Removing all elements from array. This + way we will only store active handles in them. splice(@activePorts); # Removing all elements from array. This way + we will only store active ports in them. open FILE, "<goodFile"; while (<FILE>) { # looping through all the lines in the file, one + at a time my @array=split(/ /,$_); # since entry in the file will be in +the format # filehandle port. Therefore splitting it to sto +re all the # file handles and ports in separate arrays push(@handles, $array[0]); push(@activePorts , $array[1]); } close(FILE); } } ############################################### # Function to try and recover bad connections # # If the connection is recovered it will be # # removed from the bad file and will be put # # under good file # ############################################### sub tryRecoveringBadConnections { my ($badPort) = @_; my $removeFromGoodFile="sed \'\/$badPort\/d\' goodFile > tmp &amp; +&amp; mv tmp goodFile"; print $removeFromGoodFile; open FILE, ">>badFile"; print FILE "$badPort \n"; close(FILE); } ############# # Main Code # ############# my @ports = (33333, 33334, 33335); foreach my $port (@ports) { PortConn($port); } ActivePortsAndHandles(); for (my $index=1; $index<101; $index++) { # function to set events whi +ch we will be sending across the socket push(@events, "event$index"); } my $eventCount=0; my $receiveText; my $index=0; my $thread; while($eventCount != scalar(@events)) { while (scalar(@handles)) { $index=0; foreach my $handle (@handles) { my $select = IO::Select->new(); $select->add($handle); if ($select->can_read(0.5)) { print "Can read \n"; $handle->recv($receiveText, 128); if ($receiveText eq '') { print "Lost connection to server on port $activePo +rts[$index] \n"; $handle->close; splice(@handles, $index, 1); my $badPort = $activePorts[$index]; splice(@activePorts, $index, 1); $thread = new Thread \&amp;tryRecoveringBadCon +nections, "$badPort"; } } else { $handle->send("hi"); # Error over here. Error is: Can' +t locate object method "send" via package "IO::Socket::INET=GLOB(0x12 +34gf0)" # perhaps you forgot to load "IO: +:Socket::INET=GLOB(0x1234gf0)"?) print "Data sent on port $activePorts[$index] \n"; $eventCount++; $index++; } } } } $thread->join;

Server side code just prints the message received from client. Thanks.


In reply to Re^4: Socket Handle not sending data ? by evilkamikaze
in thread Socket Handle not sending data ? by evilkamikaze

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.