小编sae*_*ati的帖子

通过 nodejs 在共享 cpanel 主机上实现 websocket 服务器

我已经获得了一个带有支持 nodejs 的 cpanel 的共享主机。我可以通过“设置 Node.js 应用程序”定义一个 node.js 应用程序。

我想做一个websocket。他们已经为我打开了 2088 端口。

这是我的 websocket 服务器代码:

const http = require('http');
const WebSocket = require('ws');

const server = http.createServer();
const wss = new WebSocket.Server({ server });

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(message) {
    console.log('received: %s', message);
  });

  ws.send('something');
});

server.listen(2088);
Run Code Online (Sandbox Code Playgroud)

好吧,我运行我的代码,然后将此请求从客户端发送到服务器:

socket = new WebSocket('ws://mydomain.com:2088');

socket.addEventListener('open', function (event) {
    socket.send('Hello Server!');
});

socket.addEventListener('message', function (event) {
    console.log('Message from server ', event.data);
});
Run Code Online (Sandbox Code Playgroud)

但是,我不断收到超时错误,无法连接到 websocket 服务器。

似乎在共享 cpanel 主机上创建一个能够侦听特定端口的 websocket 服务器与通常的有点不同。

我已经浏览了互联网,我在 …

shared-hosting passenger cpanel websocket node.js

10
推荐指数
1
解决办法
2278
查看次数

使用 'br' 编码获取页面内容并通过 php curl 对其进行解码

我想通过 php curl获取此页面的内容:

我的卷曲样本:

function curll($url,$headers=null){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);


    if ($headers){

        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    }

    curl_setopt($ch, CURLOPT_ENCODING, '');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0');
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);

    $response = curl_exec($ch);

    $res['headerout'] = curl_getinfo($ch,CURLINFO_HEADER_OUT);
    $res['rescode'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if ($response === false) {
        $res['content'] = $response;
        $res['error'] = array(curl_errno($ch),curl_error($ch));
        return $res;
    }

    $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $res['headerin'] = …
Run Code Online (Sandbox Code Playgroud)

php compression curl brotli

6
推荐指数
1
解决办法
8613
查看次数

如何按意图打开特定电报联系人的聊天页面

我想通过android意图打开特定电报联系人的聊天页面,例如@userTest。

这是意图打开的电报片段:

Intent myIntent = new Intent(Intent.ACTION_SEND);
myIntent.setType("text/plain");
myIntent.setPackage("org.telegram.messenger");
activity.startActivity(myIntent);
Run Code Online (Sandbox Code Playgroud)

但是现在如何打开特定用户的聊天页面?

android-intent telegram

5
推荐指数
1
解决办法
3127
查看次数

将 crypto.subtle.deriveKey 结果转换为十六进制字符串

根据bip39标准,我想从javascript中的助记词中获取种子

我使用这段代码:

function mnemonicToSeed(mnemonic,passphrase){
    if (typeof passphrase != 'string') passphrase='';

    window.crypto.subtle.importKey(
        'raw',
        stringToArrayBuffer(mnemonic),
        {
            name: 'PBKDF2',
        },
        false,
        ['deriveKey']
    ).then((importedKey) => {

        crypto.subtle.deriveKey({
                name: "PBKDF2",
                salt: stringToArrayBuffer('mnemonic'+passphrase),
                iterations: 2048,
                hash: { name: 'SHA-512' }
            }, 
            importedKey,
            {
                name: 'HMAC',
                hash: 'SHA-512',
                length: 512
            },
            true,
            ['sign']
        ).then(function(derivedKey) {
            console.log('derivedKey: '+derivedKey);

        });
    });

}
Run Code Online (Sandbox Code Playgroud)

但最后的结果console.log('derivedKey: '+derivedKey);是这样的:

derivedKey: [object CryptoKey]
Run Code Online (Sandbox Code Playgroud)

现在如何将衍生密钥转换为其相应的种子作为十六进制字符串?

javascript cryptography

5
推荐指数
1
解决办法
902
查看次数

如何在xaml中声明一个故事板并从代码中运行它

我想在点击按钮时增加当前窗口高度.

我用这个代码:

private void sendbtn_Click(object sender, RoutedEventArgs e)
        {
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();
            myDoubleAnimation.From = this.Height;
            myDoubleAnimation.To = 500;
            myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));

            Storyboard myStoryboard = new Storyboard();
            myStoryboard.Children.Add(myDoubleAnimation);
            Storyboard.SetTargetName(myDoubleAnimation, this.Name);
            Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Window.HeightProperty));

            myStoryboard.Begin(this); 
        }
Run Code Online (Sandbox Code Playgroud)

但我想在xaml中声明我的故事板并从代码中运行它.

但我不知道这是怎么回事?

c# wpf xaml

4
推荐指数
2
解决办法
5841
查看次数

如何在巧克力上禁用显式代理?

我在 windows cmd 中使用此命令在 Chocolatey 上启用了显式代理:

choco config set proxy http://localhost:8888
Run Code Online (Sandbox Code Playgroud)

现在我想禁用它,但不知道如何。

proxy chocolatey

4
推荐指数
1
解决办法
1605
查看次数