469,282 Members | 1,909 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

streaming data over socket

I am looking for a way to send data over a socket to a specified host and port. it is a 1 way street I am only sending the tail of a log file. Looking for something really simple that sends the tail whenever there is one. Do I need to establish a connection on the socket and is it possible with out there being a perl script at the recieving end?

Thanks for the help
Jul 31 '07 #1
4 4254
KevinADC
4,059 Expert 2GB
This is something I have little pratical experience with, but you can look into using the IO::Socket module to set up the socket communication.

http://perldoc.perl.org/IO/Socket.html

I assume there does not have to be another perl script, but there has to be something to recieve and process whatever data you send to the server.
Jul 31 '07 #2
use File::Tail;
use IO::Socket;

# init host and port
my $host = 'ip_addr';
my $port = 7777;
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(name=>$name, maxinterval=>300, adjustafter=>7);

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

$sock->send('$line');
print "$line";
}
close($sock);

Here si what I think from ready should work to send each tail of a log file over a socket. However, this does not seem to be working.

Any one have any ideas?
Jul 31 '07 #3
KevinADC
4,059 Expert 2GB
if everything else is OK, changing this ine:

$sock->send('$line');


to:

$sock->send($line);


should work.

When you put single-quotes around a scalar it literally means what is inside the quotes: $line, and not whatever value the scalar $line interpolates to. Is File::Tail installed?
Jul 31 '07 #4
Thanks for the help there.

Yes file tail module is installed, but the socket closes what seems to be every time the tail stream tries to send over that socket. I need to keep the socket open and continuously send a 1 way stream over it to a client. the connection is "established" according to netstat at both ends but the data streaming does not work.
Aug 1 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

22 posts views Thread by googlegroups | last post: by
1 post views Thread by Patty O'Dors | last post: by
1 post views Thread by bordsby | last post: by
2 posts views Thread by Changhao | last post: by
reply views Thread by Søren M. Olesen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.