我希望我不要问垃圾邮件问题,因为我找不到任何关于它的问题。我编写了一个套接字端口侦听器来侦听特定的 IP:PORT 使用 PHP 从 GPS 跟踪设备接收 TCP 数据包。当我使用此命令运行脚本时:
$php.exe -q My/Script/Files/Path.PHP
一切正常,我的服务器端口监听器工作成功,我从设备接收数据,但是当我想用我的浏览器(wamp -> localhost)打开它时,据说
Warning: socket_bind(): unable to bind address [10049]: The requested address is not valid in its context.
我该如何解决这个问题?此致。
编辑一:
我的服务器脚本代码:
<?php
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
$address = '*.*.*.*'; //I put Here My System Local IPV4 Address (163.*.*.*)
$port = *****; //I put Here My Server Opened Port Number and I turned off the firewall to test
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}
if (socket_bind($sock, $address, $port) === false) {
echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}
if (socket_listen($sock, 1) === false) {
echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}
if ($msgsock = socket_accept($sock)) === false) {
echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}
if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
}
$buf = trim($buf);
$clientResponse = explode(',', $buf);
foreach($clientResponse as $key=>$value) {
echo $key . ' : ' . $value . "<br />";
}
socket_close($msgsock);
socket_close($sock);
?>
正如我之前所说:
当我使用 PHP CLI 运行此脚本时,一切正常,我的设备发送 TCP 数据包,我的服务器接收 TCP 数据包并显示该信息。但是当我通过 wamp 使用本地 IP 127.0.0.1 运行它时,它给了我这个错误。
直到这里:
- 我有一个 VPS 服务器
- 我有一个静态 IP(公共 IP)
- 我有一个关闭防火墙的开放 TCP 端口
- 我有本地IP
- 我有一个 IP:Port -> 127.0.0.1:80 的 wamp
编辑二:
我的脚本端口:41260