gpt4 book ai didi

javascript - 使用 WebSocket 接口(interface)调用 IPV6 IP

转载 作者:IT老高 更新时间:2023-10-28 23:01:53 30 4
gpt4 key购买 nike

[我已将此问题标记为由版主删除,直到我得到 this 的答案为止问题]

我的 javascript 客户端在通过带有 IPV4 IP 地址的 WebSocket 接口(interface)与 node.js(在 Ubuntu 上,更多 here )服务器通信时工作正常。

即使我的托管服务提供商已准备好为我分配 IPV4,让我改用 IPV6,因为现在 IPV4 的供应有限。

使用 IPV6 IP 时出现此错误:

WebSocket connection to 'ws://[2600:3c00::f03c:91ff:fe73:2b08]:31333/' failed: Error in connection establishment: net::ERR_ADDRESS_UNREACHABLE

我使用工具检查了端口 31333 确实是打开的:http://www.subnetonline.com/pages/ipv6-network-tools/online-ipv6-port-scanner.php

我什至尝试过 IPv6 address giveing syntax error in internet explorer-10 websocket 中的解决方案-- 即:2600-3c00-0-0-f03c-91ff-fe73-2b08.ipv6-literal.net

我已经运行了这个客户端,并且当两者都在基于 Ubuntu 的远程服务器上运行时能够连接到服务器:

var WebSocket = require('ws')
, ws = new WebSocket('ws://[2600:3c00::f03c:91ff:fe73:2b08]:31333');
ws.on('open', function() {
ws.send('something');
});
ws.on('message', function(message) {
console.log('received: %s', message);
});

但是,当我从家里的 Windows 7 运行相同的客户端,而服务器是远程 Ubuntu 时,它无法连接:

> $ node c2.js events.js:85
> throw er; // Unhandled 'error' event
> ^ Error: connect ENETUNREACH
> at exports._errnoException (util.js:746:11)
> at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)

我什至在 Google Chrome 中运行过这段代码:

var ws = new WebSocket("ws://[2600:3c00::f03c:91ff:fe73:2b08]:31333");

ws.onerror = function(err)
{
console.log(err);
alert("Connection is error...");
};

但我得到了同样的错误:

WebSocket connection to 'ws://[2600:3c00::f03c:91ff:fe73:2b08]:31333/' failed: Error in connection establishment: net::ERR_ADDRESS_UNREACHABLE websocket.html:37 Event

可能是什么问题?

PS:目前我已经在 31333 端口停止了服务器。

最佳答案

您的 Realtek PCIe GBE 系列 Controller 上未启用 IPv6。如果是的话,ipconfig 结果中会出现一行“Link-local IPv6 Address”。

转到控制面板 > 网络 > 更改适配器设置 > 右键单击​​适配器 > 属性。检查 IPv6。

关于javascript - 使用 WebSocket 接口(interface)调用 IPV6 IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31984934/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com