Search code examples
phpperlgpstracking

How to receive GPS data on Web server?


Below is the code for a client server application for Web Server. This code is working fine i.e. first I will run server script which bind my server program to specified IP and port, after that when i run client script and connect to same IP and port, server will accept the connection and call subroutine_name subroutine in which I have created one random variable $zz and storing its data to database using test.php. This is working fine for this server client application, but when I'am trying to connect a GPS device(tk103) to the same running server script by configuring same IP and port, nothing happens. Means no connection is established between server script and GPS device.

Please help me.

This is my client script. client.pl

#!/usr/bin/perl
use cPanelUserConfig;
use strict;

print "Content-Type: text/html \n\n";
# auto-flush on socket
$| = 1;
use IO::Socket::INET;
# create a connecting socket
my $socket = new IO::Socket::INET (
    PeerHost => '199.79.62.103',
    PeerPort => '7784',
    Proto => 'tcp',
);
print "cannot connect to the server $!\n" unless $socket;
print "connected to the server\n";

# data to send to a server
my $req = 'hello world';
my $size = $socket->send($req);
print "sent data of length $size\n";

# notify server that request has been sent
shutdown($socket, 1);

# receive a response of up to 1024 characters from server
my $response = "";
$socket->recv($response, 1024);
print "received response: $response\n";

$socket->close();

This is my server script for PHP server. server.pl

#!/usr/bin/perl
use cPanelUserConfig;
print "Content-Type: text/html \n\n";
use warnings;


use IO::Socket::INET;

# auto-flush on socket
$| = 1;

# creating a listening socket
my $socket = new IO::Socket::INET (
    LocalHost => '199.79.62.103',
    LocalPort => '7784',
    Proto => 'tcp',
    Listen => 5,
    Reuse => 1
);
print "cannot create socket $!\n" unless $socket;
print "server waiting for client connection on port 7784\n";



while(1)
{
    # waiting for a new client connection
    my $client_socket = $socket->accept();

    # get information about a newly connected client
    my $client_address = $client_socket->peerhost();
    my $client_port = $client_socket->peerport();
    print "connection from $client_address:$client_port\n";
    subroutine_name();



    # read up to 1024 characters from the connected client
    my $data = "";
    $client_socket->recv($data, 1024);
    print "received data: $data\n";






    # write response data to the connected client
    $data = "ok mi";
    $client_socket->send($data);

    # notify client that response has been sent
    shutdown($client_socket, 1);
}

sub subroutine_name{
      my $filename = 'report.txt';
    open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
    print $fh "My first report generated by perl\n";
    close $fh;
    print "done\n";


     $zz='hello world my world';
    my $url = "http://www.geekzgarage.com/gps/test.php?"
      . "ln=$zz";
    # print "$url\n";
    use LWP::Simple;
    my $content = get $url;
    die "Couldn't get $url" unless defined $content;



}

$socket->close();

Solution

  • After a lot of research, I found below Git repositories which might be helpful for the developers who are trying to trace gps with their own server.

    Location.io

    Freshworkstudio

    Traccar

    I am not providing any more info regarding these links. Just check out them and you'll find the relevant info on these links itself. Cheers :)