Thread Problem mit Socket Server, reagiert zu langsam (7 answers)
Opened by Carsten at 2010-06-06 23:29

Gast Carsten
 2010-06-06 23:29
#138045 #138045
Hallo Leute,

ich habe ein Problem mit dem nachfolgenden Socketserver. Die Daten kommen in regelmäßigen Abständen von 1min an welches ich auch per netcat getestet habe.

Der Socketserver reagiert aber nur sporadisch bis gar nicht auf die Anfragen. Woran könnte das liegen ?

Vielen Dank schonmal für eure Hilfe!

Gruß
Carsten

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl

use IO::Socket;
use DBI;
$| = 1;

$dbh = DBI->connect('DBI:mysql:mydb', 'tracker', '') || die "Could not connect to database: $DBI::errstr";

my $sock = IO::Socket::INET->new(LocalHost => 'localhost', LocalPort => '12345', Proto => 'tcp',  Listen => 5, Reuse => 1) or die "Could not create socket: $!\n" unless $sock;


sub sendtomysql
{
        my $data = $_;
        chomp($data);
        # 0908242216,0033663282263,GPRMC,212442.000,A,4849.0475,N,00219.4763,E,2.29,,220809,,,A*70,F,imei:359587017313647,101Q,
        my @datas = split(/,/, $data);
        # $dbh->do('INSERT INTO exmpl_tbl VALUES(1, ?)', undef, 'Hello');

        my $trackerdate                         = $dbh->quote($datas[0]);
        my $phone                               = $dbh->quote($datas[1]);
        my $gprmc                               = $dbh->quote($datas[2]);
        my $satelliteDerivedTime                = $dbh->quote($datas[3]);
        my $satelliteFixStatus                  = $dbh->quote($datas[4]);
        my $latitudeDecimalDegrees              = $dbh->quote($datas[5]);
        my $latitudeHemisphere                  = $dbh->quote($datas[6]);
        my $longitudeDecimalDegrees             = $dbh->quote($datas[7]);
        my $longitudeHemisphere                 = $dbh->quote($datas[8]);
        my $speed                               = $dbh->quote($datas[9]);
        my $bearing                             = $dbh->quote($datas[10]);
        my $utcDate                             = $dbh->quote($datas[11]);
        # = $datas[12];
        # = $datas[13];
        my $checksum                            = $dbh->quote($datas[14]);
        my $gpsSignalIndicator                  = $dbh->quote($datas[15]);
        if($datas[16] =~ /imei/)
        {
                $imei                           = $datas[16];
                $other                          = $dbh->quote($datas[17].' '.$datas[18]);
        }
        else
        {
                $imei                           = $datas[17];
                $other                          = $dbh->quote($datas[18].' '.$datas[19]);
        }

        my $imei = $dbh->quote(substr($imei,5));

                print "INSERT INTO gprmc (date, imei, phone, trackerdate, satelliteDerivedTime, satelliteFixStatus, latitudeDecimalDegrees, latitudeHemisphere, longitudeDecimalDegrees, longitudeHemisphere, speed, Bearing, utcDate, Checksum, gpsSignalIndicator, other) VALUES (now(), $imei, $phone, $trackerdate, $satelliteDerivedTime, $satelliteFixStatus, $latitudeDecimalDegrees, $latitudeHemisphere, $longitudeDecimalDegrees, $longitudeHemisphere, $speed, $bearing, $utcDate, $checksum, $gpsSignalIndicator, $other)";
        if($gpsSignalIndicator == "'F'")
        {
                $dbh->do("INSERT INTO gprmc (date, imei, phone, trackerdate, satelliteDerivedTime, satelliteFixStatus, latitudeDecimalDegrees, latitudeHemisphere, longitudeDecimalDegrees, longitudeHemisphere, speed, Bearing, utcDate, Checksum, gpsSignalIndicator, other) VALUES (now(), $imei, $phone, $trackerdate, $satelliteDerivedTime, $satelliteFixStatus, $latitudeDecimalDegrees, $latitudeHemisphere, $longitudeDecimalDegrees, $longitudeHemisphere, $speed, $bearing, $utcDate, $checksum, $gpsSignalIndicator, $other)");
        }
        else
        {
                print $gpsSignalIndicator;
        }
}

my $new_sock;
while($new_sock = $sock->accept())
{
        while(<$new_sock>)
        {
                sendtomysql($_);
        }
}
close($sock);
$dbh->disconnect();

Last edited: 2010-06-06 23:35:22 +0200 (CEST)

View full thread Problem mit Socket Server, reagiert zu langsam