jimbo has asked for the wisdom of the Perl Monks concerning the following question:
What I have is a Perl script daemon that looks at a file using Tail and then outputs the data via a serial port. This works perfectly fine.
BUT, I wanted to ramp it up a bit and instead of outputting the data via serial, I want to send it via TCP.
I googled around, and found some pretty simple code, but I get unexpected results.
Basically, I dont get any data output until I stop the daemon...which I only stumbled upon when testing.
Here is part of my code:-
my $sock = new IO::Socket::INET ( PeerAddr => '192.168.1.2', PeerPort => '8000', Proto => 'tcp' ); while (defined(my $line=$file->read)) { print TTY "$line"; #out serial print $sock "$line"; #out tcp } close($sock);
As you can see, not exactly complex.
I tried moving the "my $sock" init of the socjet to just above the "print $sock" line, then closeing the socket, but this didnt really work.
I tried $sock->send(); but this didnt make any difference.
I am sure someone will spot the problem beable to tell.
Thanks, Jeremy
Edit: g0n - code tags & formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Sockets question
by moritz (Cardinal) on Feb 08, 2008 at 23:01 UTC | |
by jimbo (Initiate) on Feb 08, 2008 at 23:16 UTC | |
by redgreen (Priest) on Feb 09, 2008 at 03:41 UTC | |
by jimbo (Initiate) on Feb 09, 2008 at 04:28 UTC | |
by moritz (Cardinal) on Feb 09, 2008 at 08:58 UTC | |
| |
|
Re: Perl Sockets question
by zentara (Cardinal) on Feb 09, 2008 at 16:42 UTC |