Skip to content

Instantly share code, notes, and snippets.

@takeshy
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takeshy/9088ae4f61dae3b635a5 to your computer and use it in GitHub Desktop.
Save takeshy/9088ae4f61dae3b635a5 to your computer and use it in GitHub Desktop.
socket.ioでiPhone,Androidでローディングが続く問題
var static = require('node-static');
var file = new static.Server('.');
server = require('http').createServer(function (request, response) {
request.addListener('end', function () {
file.serve(request, response);
}).resume();
})
server.listen(60000);
var io = require('socket.io').listen(60001);
io.sockets.on('connection', function(socket){
socket.on('message', function(){
socket.emit("reply","hello");
});
socket.on('disconnect', function(){});
});
<!DOCTYPE html>
<html>
<head>
<title>sample</title>
</head>
<body>
<div id="Continar">
</div>
<script src="http://49.212.183.126:60001/socket.io/socket.io.js"></script>
<script>
setTimeout(function(){
var socket = null;
if(/iPhone|iPod|iPad/i.test(navigator.userAgent)){
socket = io.connect('http://49.212.183.126:60001',{transports: ["websocket","polling"]});
}else{
socket = io.connect('http://49.212.183.126:60001',{forceJSONP: true});
}
socket.on('connect', function(){
socket.emit("message","Hello World!");
socket.on('reply', function(msg){
document.getElementById("Continar").innerHTML = msg;
});
});
},0);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment