如何在 Web 服务器上接收 GPS 数据?
How to receive GPS data on Web server?
以下是 Web 服务器的客户端服务器应用程序的代码。这段代码工作正常,即首先我将 运行 服务器脚本将我的服务器程序绑定到指定的 IP 和端口,之后当我 运行 客户端脚本并连接到相同的 IP 和端口时,服务器将接受连接并调用 subroutine_name 子程序,我在其中创建了一个随机变量 $zz 并使用 test.php[=25= 将其数据存储到数据库中].
这对于这个服务器客户端应用程序来说工作正常,但是当我试图通过配置相同的 IP 和端口,没有任何反应。意味着服务器脚本和 GPS 设备之间没有建立连接。
请帮帮我
这是我的客户端脚本。 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();
这是我的 PHP 服务器脚本。 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();
经过大量研究,我在下面找到了 Git 个存储库,这些存储库可能对尝试使用自己的服务器跟踪 gps 的开发人员有所帮助。
我不会提供有关这些链接的更多信息。只需查看它们,您就会在这些链接本身上找到相关信息。
干杯:)
以下是 Web 服务器的客户端服务器应用程序的代码。这段代码工作正常,即首先我将 运行 服务器脚本将我的服务器程序绑定到指定的 IP 和端口,之后当我 运行 客户端脚本并连接到相同的 IP 和端口时,服务器将接受连接并调用 subroutine_name 子程序,我在其中创建了一个随机变量 $zz 并使用 test.php[=25= 将其数据存储到数据库中]. 这对于这个服务器客户端应用程序来说工作正常,但是当我试图通过配置相同的 IP 和端口,没有任何反应。意味着服务器脚本和 GPS 设备之间没有建立连接。
请帮帮我
这是我的客户端脚本。 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();
这是我的 PHP 服务器脚本。 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();
经过大量研究,我在下面找到了 Git 个存储库,这些存储库可能对尝试使用自己的服务器跟踪 gps 的开发人员有所帮助。
我不会提供有关这些链接的更多信息。只需查看它们,您就会在这些链接本身上找到相关信息。 干杯:)