douzhu3654 2016-04-29 10:05
浏览 143
已采纳

PHP socket_connect()不连接到本地IP

I'm trying to work with teamspeak on my pc, but because of simplicity I wanna use my raspberry PI to execute the script, so I'm just writing my script:

<?php
error_reporting(E_ALL);
ob_implicit_flush();

$address = "192.168.2.11";
$service_port = 25639;

$socket = socket_create(AF_INET, SOCK_STREAM, 0);
if($socket === false)
{
    die("Error: " . socket_strerror(socket_last_error())."
");
}
echo "Connecting to {$address}:{$service_port}...
";
$result = socket_connect($socket, $address, $service_port);
if($result === false)
{
    die("Error: ".socket_strerror(socket_last_error($socket))."
");
}
echo socket_read($socket, 512);
?>

But everytime I run it, it just gives me:

Connecting to 192.168.2.11:25639...

and no further messages. I am thinking the error is at socket_create, but changing the parameters just throws errors.

I googled and searched on stack, but it looks like I'm the only one that has this issue. :/

  • 写回答

1条回答 默认 最新

  • doumao1047 2016-04-29 10:48
    关注

    Try running this:

    <?php
    $host="192.168.2.11" ;
    $port=25639;
    $timeout=30;
    $sk=fsockopen($host,$port,$errnum,$errstr,$timeout) ;
    
    if (!is_resource($sk)) {
        exit("connection fail: ".$errnum." ".$errstr) ;
    } else {
        echo "Connected";
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题