hi monks,
i have the following code that works 100%
basically i have a open port and it listens for connections then once a connection is established it saves all the data to a log file,
the problem is the connection will stay open for 12 hrs + and keep sending data,
so how can i save the second and third etc connection's data,
i might hve up to 50 connections at a time
here is my existing code
#!/usr/bin/perl -w
my $socket;
my $port = 7777;
my $host;
use IO::Socket;
use Sys::Hostname;
$host = hostname();
my $sock = new IO::Socket::INET(
LocalHost => $host,
LocalPort => $port,
Proto => 'tcp',
Listen => 5,
Reuse => 1,
);
if (!$sock){
die "no socket :$!";
}
my($new_sock, $c_addr, $buf);
#open($log, '>>', 'log.txt') || die "Couldn't open log.txt: $!";
while (($new_sock, $c_addr) = $sock->accept())
{
my ($client_port, $c_ip) =sockaddr_in($c_addr);
my $client_ipnum = inet_ntoa($c_ip);
my $client_host =gethostbyaddr($c_ip, AF_INET);
print "got a connection from: $client_host"," [$client_ipnum] ";
while (defined ($buf = <$new_sock>))
{
open ($log, '>>','log.txt') || die "Couldn't open log.txt: $!";
print $buf;
print $log $buf;
close $log;
}
}
and here is an example of data recieved
$MENQ,run,l1, 0E13,,839469
$GPRMC,152457.001,A,2232.3347,N,11401.2021,E,0.2,017.0,180507,,,A*66
$MENQ,run,c9, 0E13,,839469
$GPRMC,152612.001,A,2232.3722,N,11401.2106,E,0.1,194.9,180507,,,A*66
$MENQ,run,f9, 0E13,,839469
$GPRMC,152642.001,A,2232.3245,N,11401.1969,E,0.1,198.0,180507,,,A*60
$MENQ,run,f9, 0E13,,839469
$GPRMC,152642.001,A,2232.3245,N,11401.1969,E,0.1,198.0,180507,,,A*60
thanks
K-
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.