php socket socket_bind()无法绑定地址[10013]



我的情况:

  • 我有一个程序,该程序在某些机器上发送了许多数据。
  • 我可以从telnet连接中检索该数据。

telnet步骤:

  • 以CMD为admin
  • 启动
  • 写telnet并发送
  • 写"打开Localhost 4448"并发送
  • 写" Get XX,YY"
  • 之后,我刚刚在LIVE中阅读了屏幕信息

xx和yy是标识机器

的数字

现在让我们在PHP侧,我有我的index.php,但是当我执行套接字时,它会给我一个错误(在代码下报告)和关于代码的错误,这来自:http://php.net/手册/en/en/sockets.examples.php及其第一个示例,我阅读并尝试了此解决方案。两种情况我都会遇到相同的错误...

<?php
error_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting
 * as it comes in. */
ob_implicit_flush();
$address = 'localhost';
$port = 4448;
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, 5) === false) {
    echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "n";
}
do {
    if (($msgsock = socket_accept($sock)) === false) {
        echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "n";
        break;
    }
    /* Send instructions. */
    $msg = "GET xx,yy";
    socket_write($msgsock, $msg, strlen($msg));
    do {
        if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
            echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "n";
            break 2;
        }
        if (!$buf = trim($buf)) {
            continue;
        }
        if ($buf == 'quit') {
            break;
        }
        if ($buf == 'shutdown') {
            socket_close($msgsock);
            break 2;
        }
        $talkback = "PHP: You said '$buf'.n";
        socket_write($msgsock, $talkback, strlen($talkback));
        echo "$bufn";
    } while (true);
    socket_close($msgsock);
} while (true);
socket_close($sock);
?>

这是我遇到的错误:

警告:socket_bind():无法绑定地址[10013]:尝试是 通过其访问权限禁止的方式访问插座

我已经在寻找管理员特权,我认为这一切都很好。

额外信息:我正在使用PHP 7,我的Web服务器是XAMPP软件包中的Apache。

可能已经使用了另一个程序正在使用该端口。尝试使用其他端口。如果有效,您可以尝试使用端口并终止该过程。该工具来自Sysinternals可能会有所帮助:https://learn.microsoft.com/en-us/sysinternals/downloads/tcpview

如果使用其他端口也失败,则可能是您有一个不允许绑定的防火墙。尝试暂时禁用防火墙。

最新更新