Last active
August 29, 2015 14:02
-
-
Save takeshy/9088ae4f61dae3b635a5 to your computer and use it in GitHub Desktop.
socket.ioでiPhone,Androidでローディングが続く問題
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(){}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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