使用套接字的 PHP 多播服务器 [英] PHP Multicast server using sockets

查看:63
本文介绍了使用套接字的 PHP 多播服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码在 PHP 中创建多播服务器:

I'm trying to create a multicast server in PHP using the following code:

$this->sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($this->sock, IPPROTO_IP, MCAST_JOIN_GROUP, ['group' => '255.1.1.1', 'interface' => "eth0"]);
socket_set_option($this->sock, IPPROTO_IP, IP_MULTICAST_TTL, 2);

但我收到错误:

socket_set_option(): 无法设置套接字选项 [22]: 无效参数

socket_set_option(): unable to set socket option [22]: Invalid argument

在线设置MCAST_JOIN_GROUP.我似乎无法在网上找到很多与 PHP 多播服务器相关的信息.有没有人遇到过这个问题?

On the line setting MCAST_JOIN_GROUP. I can't seem to find much info related to PHP multicast servers online. Does anyone have experience with this problem?

我在 ubuntu 14.04.2 VMWare 7.1.2 VM 上使用 PHP 5.5.9.我已验证 eth0 是 VM 上的主要网络接口.

I'm using PHP 5.5.9 on a ubuntu 14.04.2 VMWare 7.1.2 VM. I have verified that eth0 is the primary network interface on the VM.

推荐答案

我认为您的问题是您的 MCcast 地址选择.请参阅:如何选择多播地址我的应用程序的用途? – Sammitch

I think your problem is your MCcast address selection. See: How do I choose a multicast address for my application's use? – Sammitch

我想输入 225.我的大脑正在阻止错误的 IP 地址,因为它甚至是一种遥远的可能性.– 罗布

I meant to type 225. My brain was blocking that out the wrong IP address as even being a remote possibility. – Rob

这篇关于使用套接字的 PHP 多播服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆