socket.io在台式机上工作,但不在移动设备上工作(类似问题没有解决方案)

时间:2019-05-26 18:56:54

标签: node.js mobile socket.io

我正在尝试使用socket.io设置一个websocket,以从服务器获取通知。

一切都可以从桌面客户端正常运行。甚至通过远程测试验证。付费插座始终有效。确认的套接字有时会出现问题。

在移动客户端上-特别是IOS(未尝试过Andriod),所有套接字都不起作用。

另外,关于socket.io体系结构的一个更普遍的问题:

此应用程序可用于接收比特币付款。 每次打开网站时,都会对节点进行api调用以获取新地址。会话使用rooms =链接到该地址,在这种情况下,由“ id”引用。然后,通过套接字发送的所有后续消息都使用该地址进行过滤=>它们基本上是对给定地址付款的更新。

thewebsite.com是任意的。我们没有使用本地主机。这是一个经过验证的tls域。

任何其他建议都将受到欢迎,并将得到重视。

我使用完全相同的设置,但是使用了http服务器,并且各种解决方案使我转换为https-尽管nginx已经在处理ssl。

CLIENT SIDE JS

let socket = io();
socket.connect("https://thewebsite.com/");

socket.on('paid', function(msg){
    console.log(msg);
    const amount_paid = parseFloat(msg.message.amount);
    received(amount_paid);

});
socket.on('confirmed', function(msg){
    console.log(msg);
    const amount_paid = parseFloat(msg.message.amount);
    confirmed(amount_paid);

});
...
...
get_address()
.then((result)=>{
    address = result;
    socket.emit('id', {"address": address});
    console.log(address);
})
.catch((e)=>{
    console.log(e);
});
...
...
...

服务器端JS

const express = require('express');
const app = express();

const read = require('fs').readFileSync;


const credentials = {
  "key": read(`${process.env.SSL}thewebsite.key`, 'utf8'),
  "cert": read(`${process.env.SSL}thewebsite.crt`, 'utf8'),
  "ca": [
    read(`${process.env.SSL}tan_ca1.pem`, 'utf8'),
    read(`${process.env.SSL}tan_ca1.pem`, 'utf8'),
    read(`${process.env.SSL}tan_ca1.pem`, 'utf8')
  ]
};
const server = require('https').createServer(credentials, app);
const io = require('socket.io').listen(server);
...
...
...
app.post('/paid', (req,res)=>{
    try{
        //console.log(req.body.secret);
        let data = req.body;
        //the node will call this end point when new transaction is received
        if(data.secret === process.env.PIDGEY_SECRET){
            delete data.secret;
            console.log(data.address);

            io.to(`${data.address}`).emit('paid', {status:true, message: data});


            res.status(200).send({status: true, message:`pidgey knows about ${data.address}`});
        }
        else{
            res.status(400).send({status: false, message:"not my address"});

        }
    }
    catch(e){
        res.status(400).send({status: false, message:"error"});
        console.log(`Broke at the outskirts of btc_received.\n\nHere is the full error: ${e}`);
    }
});
...
...
...
io.sockets.on('connection',(socket) =>{
    console.log("Suser live.")
    socket.on('disconnect', function(){
        console.log('sUser disconnected.');
    });
    socket.on('id',function(msg){
        socket.join(msg.address);
        console.log(msg.address);
    });
})

NGINX

        server{
                listen                  443 ssl;
                server_name             thewebsite.com www.thewebsite.com;
                ssl                     on;
                gzip                    on;
                ssl_certificate         /etc/nginx/ssl/thewebsite_certchain.crt;
                ssl_certificate_key     /etc/nginx/ssl/thewebsite.key;

                location / {
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_set_header Host $http_host;
                        proxy_set_header X-NginX-Proxy true;
                        proxy_redirect off;
                        proxy_http_version 1.1;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection "upgrade";

                        proxy_redirect off;
                        proxy_set_header   X-Forwarded-Proto $scheme;
                        proxy_pass      https://localhost:3000/;

                }


        }

预期在IOS上获得更新。一无所获。使用chrome:// inspect时无更新。

0 个答案:

没有答案