diazocon has asked for the wisdom of the Perl Monks concerning the following question:
and the other sends lines like: ##,imei:354779033965634,A; and sits there, waiting for the server to reply LOAD and then it replies back with the actual GPS data. I have been reading and using multiple approaches, but the hard thing its that the GPS dont send newline chars, so many solutions (such as NetServer::Generic or IO:Socket*...) don't work. Long story short, I was able to parse the first format with read but I still need to be able to get the other message, reply with LOAD and get the text. Once I get that text, I could process it with a regex... but I am still away from there, Any advice? Here is my code (which I also borrowed and modified from here):(013632782450BP05000013632782450101005A2038.3383N10315.1368W000.004122 +0116.4900000000L00000000)(013632782450BP05000013632782450101005A2038. +3383N10315.1368W000.0041225116.4900000000L00000000)(013632782450BP050 +00013632782450101005A2038.3383N10315.1368W000.0041255116.4900000000L0 +0000000)(013632782450BP00000013632782450HSO)(013632782450BP0500001363 +2782450101005A2038.3383N10315.1368W000.0041325116.4900000000L00000000 +)
Thank you All! Carlos#!/usr/bin/perl -w -T package MyPackage; use strict; use base qw(Net::Server::PreFork); MyPackage->run({port => 9000, no_client_stdout => 1}); sub process_request { my $self = shift; eval { local $SIG{'ALRM'} = sub { die "Timed Out!\n" }; my $timeout = 5; my $sock = $self->{server}->{client}; $sock->autoflush(1); $|=1; binmode $sock; my $buf; while (read ($sock, $buf, 94) != 0 ){ #sleep(5); print $sock "client said '$buf'\r\n"; print "client said '$buf'\r\n"; alarm($timeout); } print $buf; alarm(0); }; if ($@ =~ /timed out/i) { print STDOUT "Timed Out: $@.\r\n"; return; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reply to TCP messages Net::Server::PreFork
by sflitman (Hermit) on Oct 07, 2010 at 05:46 UTC | |
by diazocon (Initiate) on Oct 07, 2010 at 15:06 UTC | |
by Anonymous Monk on Feb 15, 2012 at 12:54 UTC |