Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

socket streaming of data

Status
Not open for further replies.

cookspyder

IS-IT--Management
Aug 1, 2007
4
US
I am trying to create a piece of code to open a continous socket and stream a file tail over it every time that file has a new line. The code does open the socket however no data is ever sent to the other end that i can tell. And when ever there is new data written to the tailed file the and what I assume is sent over/to the socket it closes the connection. Does any one know of a way to get thsi working?
Currently I know the tail is working because on the console I can see it print the tails as it sees new lines written but it is not sending them as far as i can tell over the socket.
Here is the code snippet.

use File::Tail;
use IO::Socket;

# init host and port
my $host = 'IP_ADDR';
my $port = 5820;
my $name = 'C:\requestDiag.log';
my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp');
$sock or die "no socket: $!";

$file=File::Tail->new("requestDiag.log");

while (defined($line=$file->read)) {

$sock->send($line.'\n');
print "$line";
}

Thanks
 
Did you write the receiver also? Maybe the problem is there?
At a glance your code looks good.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Yea the reciever is an app set to server socket and the identified port. Its not a perl based app its javascript and java.

So i cant change much on that end. Was hoping perl would be able to be one sided in the socket connection and push the data over the socket.
 
It can it your code looks fine to me. You should create socket receiver and send to your self and see if you get the data.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top