如何在Web服务器上接收GPS数据?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Web服务器上接收GPS数据?相关的知识,希望对你有一定的参考价值。
下面是Web Server的客户端服务器应用程序的代码。这段代码工作正常,即首先我将运行服务器脚本,将我的服务器程序绑定到指定的IP和端口,之后当我运行客户端脚本并连接到相同的IP和端口时,服务器将接受连接并调用subroutine_name子例程,其中我创建了一个随机变量$ zz,并使用test.php将其数据存储到数据库中。这适用于此服务器客户端应用程序,但是当我尝试通过配置相同的IP和端口将GPS设备(tk103)连接到相同的运行服务器脚本时,没有任何反应。表示服务器脚本和GPS设备之间没有建立连接。
请帮我。
这是我的客户端脚本。 client.pl
#!/usr/bin/perl
use cPanelUserConfig;
use strict;
print "Content-Type: text/html
";
# 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 $!
" unless $socket;
print "connected to the server
";
# data to send to a server
my $req = 'hello world';
my $size = $socket->send($req);
print "sent data of length $size
";
# 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
";
$socket->close();
这是我的PHP服务器的服务器脚本。 server.pl
#!/usr/bin/perl
use cPanelUserConfig;
print "Content-Type: text/html
";
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 $!
" unless $socket;
print "server waiting for client connection on port 7784
";
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
";
subroutine_name();
# read up to 1024 characters from the connected client
my $data = "";
$client_socket->recv($data, 1024);
print "received data: $data
";
# 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
";
close $fh;
print "done
";
$zz='hello world my world';
my $url = "http://www.geekzgarage.com/gps/test.php?"
. "ln=$zz";
# print "$url
";
use LWP::Simple;
my $content = get $url;
die "Couldn't get $url" unless defined $content;
}
$socket->close();
答案
经过大量的研究,我在Git存储库下面找到了可能对试图用自己的服务器跟踪gps的开发人员有用的东西。
我没有提供有关这些链接的任何更多信息。只需查看它们,您就可以在这些链接上找到相关信息。干杯:)
以上是关于如何在Web服务器上接收GPS数据?的主要内容,如果未能解决你的问题,请参考以下文章
如何接收 GPS 位置并膨胀 Fragment MapView 以使用 SyncAdapter 以编程方式添加标记
将 Gps 作为后台服务运行并将接收到的当前位置数据与 Sqlite 中的值进行比较?