【发布时间】:2013-07-15 21:00:35
【问题描述】:
我正在尝试使用 PHP socket_connect() 函数连接用 C 编写的目标,但出现以下错误:
警告:socket_connect(): 无法连接 [10061]: 由于目标机器主动拒绝,无法建立连接。
这是我正在运行的代码:
$service_port = 1234;
$address = "xx.xxx.xx.xxx";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
echo "OK.\n<br>";
}
echo "Attempting to connect to '$address' on port '$service_port'...\n";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
echo "OK.\n<br>";
}
我在 Windows 7 中使用带有 PHP 5.4 的 xampp 服务器,并且我禁用了防火墙设置。我仍然收到同样的拒绝错误。
请帮我解决这个问题。 [过去 3 天我一直在与这个问题作斗争]
提前致谢。
【问题讨论】:
-
你的 $address 是什么? $address机器中的$service_port是否被防火墙允许?
-
是的。我的 $service 端口被允许使用 $address。如果我使用 Visual Studio 2010 - Windows 应用程序进行检查,我的基于 C 的目标正在与客户端通信,而不是与 PHP 套接字连接。
-
@Kumar 你试过重新安装 WAMP 吗?
-
检查这个。 link
标签: php sockets tcp xampp warnings