节点https服务器socket.io传输websocket无法在safari中运行,但在其他浏览器(chrome,firefox)中也能正常运行

时间:2019-02-27 05:50:19

标签: ios https socket.io

node https项目在PC浏览器(chrome firefox)中一切正常,但是在ios(ipad,iphone)safari中运行该项目时,socket.io(transport:[“ websocket”])无法正常工作,但是当我将传输更改为轮询,它可以工作,但是套接字连接通常会断开连接(

index.js:83 POST http://localhost:3000/socket.io/?serialNumber=SP75111&EIO=3&transport=polling&t=MajUroN&sid=u76RcG7ofRkgorCJAAAA 400 (Bad Request)

index.js:83 POST http://localhost:3000/socket.io/?serialNumber=SP75111&EIO=3&transport=polling&t=MajUrtH&sid=u76RcG7ofRkgorCJAAAA 400 (Bad Request)), So the connection is always: reconnected, disconnected.....

有人有解决方案吗?有任何想法吗? app.js:

let socketIo = require("socket.io")
let webSocket = require('./websocket');
if (config.certConfig.enable) {
    io = socketIo(httpsServer, {
        pingInterval: 8000,
        pingTimeout: 12000,
        transport: ['websocket','polling'],
        path: "/socket.io"
    });
} else {
    io = socketIo(httpServer, {
        pingInterval: 8000,
        pingTimeout: 12000,
        transport: ['websocket','polling'],
        path: "/socket.io"
    });
}
webSocket.webSockets(io);

index.html:

var async = new Promise(function (resolve, reject) {
        var downloadIndexLoading = showLoadMessage(MESSAGE[0].BBMES_00053);

        let reconnectFlag = false;
        let serialNumberStr = "?serialNumber=" + machineParams.serialNumber;
        var socket = io(window.location.protocol + "//" + window.location.host + "/preload" + serialNumberStr, {
            transports: ['websocket','polling'],
            forceNew: true,
            path: "/socket.io",
            'reconnection': true,
            'reconnectionDelay': 1000,
            'reconnectionDelayMax': 5000,
            'reconnectionAttempts': 5
        });
        socket.on('connect', () => {
            let preloadData = {
                serialNumber: machineParams.serialNumber,
                machineModel: machineParams.machineModel,
                tableType: machineParams.tableType,
                processType: machineParams.processType,
                machineTypeId: machineParams.machineTypeId,
                mvtParameter: JSON.stringify(machineParams.mvtParameter),
                encoderType: machineParams.encoderType,
                userName: machineParams.userName,
                empNo: machineParams.empNo,
                isAtpp: machineParams.isAtpp
            }
            if (!reconnectFlag) {
                socket.emit('isPreLoadData', preloadData);
            }
        });
        socket.on('reconnect', () => {
            reconnectFlag = true;
        });

        socket.on('preLoadResult', function (data) {
           ...
            socket.close();
        })
    });
    return async;

0 个答案:

没有答案