gpt4 book ai didi

javascript - 401 使用 Node.js 的混合中继连接

转载 作者:太空宇宙 更新时间:2023-11-04 00:26:42 28 4
gpt4 key购买 nike

我刚刚运行 Microsoft 的示例代码来使用 node.js 测试混合中继连接

运行:

Node 监听器.js

产生以下错误:

错误错误:意外的服务器响应(401)

这是我的代码( Node listener.js)...

    const WebSocket = require('hyco-ws');

const ns = "hcrelay.servicebus.windows.net";
const path = "hc1";
const keyrule = "hc1key";
const key = "Password@1234";

var wss = WebSocket.createRelayedServer(
{
server : WebSocket.createRelayListenUri(ns, path),
token: WebSocket.createRelayToken('http://' + ns, keyrule,key)
},
function (ws) {
console.log('connection accepted');
ws.onmessage = function (event) {
console.log(event.data);
};
ws.on('close', function () {
console.log('connection closed');
});
});

console.log('listening');

wss.on('error', function(err) {
console.log('error' + err);
});

最佳答案

我尝试了你的代码,效果很好。关键是我将 keyrule 设置为共享访问策略的名称,并将 key 设置为共享访问策略的主键。

const WebSocket = require('hyco-ws');

const ns = "hcrelay.servicebus.windows.net"; // Relay namespace
const path = "hc1"; // Hybrid connection name
const keyrule = "RootManageSharedAccessKey"; // Policy name
const key = "sjSqVUo..."; // Primary key

var wss = WebSocket.createRelayedServer(
{
server : WebSocket.createRelayListenUri(ns, path),
token: WebSocket.createRelayToken('http://' + ns, keyrule,key)
},
function (ws) {
console.log('connection accepted');
ws.onmessage = function (event) {
console.log(event.data);
};
ws.on('close', function () {
console.log('connection closed');
});
});

console.log('listening');

wss.on('error', function(err) {
console.log('error' + err);
});

enter image description here

enter image description here

关于javascript - 401 使用 Node.js 的混合中继连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42488582/

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