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

岁酱吖の 提交于 2019-12-12 18:14:03

问题


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>

来源:https://stackoverflow.com/questions/37786203/node-js-socket-io-app-not-working-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!