Hi gurus
I need to listen a TCP socket for a specifig string, take that string and make something with it.
So far I have no luck and here is my code:
---------------------- START --------------------------
--
#!/usr/bin/perl -w
use IO::Socket::INET;
use LWP::UserAgent;
use IO::Socket;
# Open LOG file for debug
open (LOG,">>/tmp/log.txt");
#Open socket
$MySocket=new IO::Socket::INET->new(List
en => 5,
LocalPort => 3319,
Proto => 'tcp') or die "$!" unless $sock;
# Next we need to wait so long, that we receive a string "PROG_ID xxxxxxx" ,where xxxx is a some ASCII string. Time to wait is from few seconds to 6 hours
while(1)
{
$MySocket->recv($ID,512);
print LOG "From socket $ID\n"; # Are we getting any
if ($ID =~ /^PROG_ID/)
{
print LOG "IF-LAUSEESSA: $ID\n";
$ID =~ s/PROGRAM_START //; #RIP off "PROG_ID and leave only ASCII string
print LOG "ASCII ID is: $ID\n";
}
}