- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试在部署在不同网络(均在 NAT 之后)的机器上的两个 PHP 守护程序之间建立 P2P。我在 Google 上搜索了使用 PHP 的 NAT 遍历,似乎他们在 PHP 中没有针对此问题的现有解决方案。
有人知道用 PHP 解决这个问题的解决方案/库吗?
最佳答案
如果其他人正在寻找答案,这里有一个简单的类可以完成这项工作:
<?php
class STUNClient
{
private $socket;
public function __construct()
{
//stun.l.google.com
$this->setServerAddr("66.102.1.127", 19302);
$this->createSocket();
}
public function setServerAddr($host, $port = 3478)
{
$this->serverIP = $host;
$this->serverPort = $port;
}
public function createSocket()
{
$this->socket = socket_create(AF_INET, SOCK_DGRAM, getprotobyname("udp"));
socket_set_nonblock($this->socket);
}
public function getPublicIp()
{
$msg = "\x00\x01\x00\x08\xc0\x0c\xee\x42\x7c\x20\x25\xa3\x3f\x0f\xa1\x7f\xfd\x7f\x00\x00\x00\x03\x00\x04\x00\x00\x00\x00";
$numberOfBytesSent = socket_sendto($this->socket, $msg, strlen($msg), 0, $this->serverIP, $this->serverPort);
$st = time();
while (time() - $st < 1) {
socket_recvfrom($this->socket, $data, 32, 0, $remoteIP, $remotePort);
if (strlen($data) < 32) {
continue;
}
break;
}
try {
$info = unpack("nport/C4s", substr($data, 26, 6));
$ip = sprintf("%u.%u.%u.%u", $info["s1"], $info["s2"], $info["s3"], $info["s4"]);
$port = $info['port'];
return [
'ip' => $ip,
'port' => $port
];
} catch (Exception $e) {
return [
'ip' => "0.0.0.0",
'port' => "0"
];
}
}
}
它是这样使用的:
$sc = new STUNClient;
print_r( $sc->getPublicIp() ); //prnints out the public ip and port
关于php - PHP 中的任何 STUN/TURN/ICE 客户端库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4213805/
刚读 this article ,这让我很想知道加快谈判阶段的好处。我正在开发一个应用程序,其中我使用的是仅使用 ICE 的第三方实用程序,但最终将在下一个版本中升级为涓流 ICE。升级需要相当多的代
您好,我使用 Zeroc Ice 通信库 (v3.4.2) 编写了一个 C# 客户端/服务器应用程序。 我正在从服务器传输一系列对象,然后以表格格式在客户端中显示它们。很简单。 我定义了以下切片类型
未捕获的 DOMException:构建“RTCPeerConnection”失败:当 URL 方案为“turn”或“turns”时,需要用户名和凭据。 我收到这个错误是因为我使用的是 ice 服务器
我的本地计算机上的 WiX 遇到一些奇怪的问题。该问题是间歇性的,但在对解决方案进行几次重建后,WiX 项目开始抛出 ICE 验证错误。 如果我进入 AppData\Local\Temp 文件夹并
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 个月前。 Improve this q
我使用 WiX 3.5 构建了一个安装程序。安装程序使用 VB6 合并模块。我总是从与此类似的灯光中收到很多错误消息: error LGHT0204: ICE03: Table: Class Colu
我正在尝试使用 TFS 将 WiX 集成到我的自动构建解决方案中2010 运行于 Windows Server 2008 R2。一切似乎都很简单,然后我明白了: light.exe: Error ex
我正在遵循 Licode page 上的指南 我已经在 Ubuntu 14.04 上安装了所有内容。 我已经在 licode_config.js 中为 licode 和 erizo Controlle
我正在使用 WebRTC API 在运行在 chrome 浏览器上的两台 PC 之间进行视频通话。我的观察是只有当我连接到互联网时才会生成 ICE 候选者,否则不会生成 ICE 候选者。为什么会这样?
我的树表中有很多命令链接,我动态构建它们,如果我想在单击一个命令链接时更改它的颜色,所有命令链接都会更改它们的颜色,我不知道如何做更改此指定链接的颜色,因为我不知道她的号码或 ID,如果有人知道答案,
假设我有这样的功能(在 Javascript 中): 功能乐趣(success_cb,error_cb){ 变量结果; 尝试 { 结果 = function_that_calculates_resul
不要在 safari 中工作示例 https://github.com/Kurento/kurento-tutorial-node/tree/master/kurento-one2many-call
视频通话在同一网络内工作正常。问题是在其他网络上调用计算机时,远程视频不显示。在 chrome 上,我在控制台中没有收到任何错误,但在 firefox 控制台上,我收到了“ICE Failure”。
我遇到了 ZeroC ICE 字典语法的新手问题。这是我尝试过的方法,但似乎没有任何效果。 /*What I want to make >*/ dictionary> FlightSchedule;
此菜单不适用于任何 IE 版本。我怎样才能让它工作? 我也想添加过渡,有没有办法添加它以便从顶部缓慢打开? http://tinyurl.com/7rxskdj #nmenu {width:700px
我正在开发两个对等点之间的信号系统,并注意到 RTCPeerConnection.onicecandidate 事件没有触发。我检查了 iceGatheringState,它总是返回"new",这意味
我想利用 ICE Faces fileInput 控件根据用户选择的文件为网页上的输入字段输入文件路径和文件名。如何在不实际执行任何文件传输操作的情况下捕获这些属性? 最佳答案 我相信真正的答案是你不
我已经阅读了 RFC 5389 和 RFC 5245 以及更新的 RFC 8445。我了解 STUN 如何返回服务器反身地址或中继地址。请求被发送到 STUN 服务器。 我的基本问题是关于使用 STU
我正在开发一个 iOS 应用程序,使用 WebRTC 与 RTCDataChannel 进行点对点数据通信。当两个设备都在同一个 wifi 网络上时,我已经设法让一切正常工作,但是当我将 1 放在移动
我正在尝试建立 b/w 两个对等点的 p2p 音频/视频连接。以下:Getting started with WebRTC . 它在我家的两台 PC 之间的 LAN 环境中运行良好,但在运行时抛出错误
我是一名优秀的程序员,十分优秀!