Node.js + socket.io app not working in iphone

2019-07-17 19:31发布

问题:

I have an issue with node js + socket io which are not working with iphone safari browser and chrome browser. It's working with desktop browsers as well with android phone browsers.

In http case it working well with iphone browsers. The only issue with https case that not working with iphone. Here is my code

app.js

var fs = require('fs');
var https = require('https');

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

var options = {
  key: fs.readFileSync('./key.pem'),
  cert: fs.readFileSync('/cert.pem')
};
var serverPort = 3008;

var server = https.createServer(options, app);
var io = require('socket.io-client')(server);

app.get('/', function(req, res) {
  res.sendFile(__dirname + '/node_test/index.html');
});

io.on('connection', function(socket) {
//  console.log('new connection');

setInterval(function(){

var timeout = new Date().getTime();
  socket.emit('message', timeout);
});

},1000);

server.listen(serverPort, function() {
  console.log('server up and running at %s port', serverPort);
});

index.html

<script src="/socket.io-client/socket.io.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script>
  var URL_SERVER = 'https://www.example.com:3008';
  var socket = io.connect(URL_SERVER);
  socket.on('message', function(data) {
jQuery('#show_time').html(data); 
      });
    </script>
<div id="show_time">time....</div>