{"issue":{"state":"open","created_at":"2011-11-19T13:03:06Z","updated_at":"2011-12-08T10:21:44Z","comments":5,"user":{"gravatar_id":"6d5e719df2d45ddc051b4c0a46679a3e","id":460586,"url":"https://api.github.com/users/Juriy","avatar_url":"https://secure.gravatar.com/avatar/6d5e719df2d45ddc051b4c0a46679a3e?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"Juriy"},"body":"Hello guys, I've seen that there are couple more topics on the subject, but I still couldn't find the andswer to the question. So here's the problem: Android continiously reconnects to the server as the new client. \r\n\r\nLittle bit more details on the subject.\r\n\r\n### Client\r\n* Device: Samsung Galaxy (GT-I9000)\r\n* Android version: 2.2\r\n* Build number: FROYO.XWJP6\r\n\r\n### Server\r\n* Node.js version: v0.6.1 running on Windows 7\r\n* Socket IO version: 0.8.7\r\n\r\n### List of installed modules (npm ls)\r\n```\r\n+-- async@0.1.15\r\n+-- ejs@0.4.3\r\n+-T express@2.5.0\r\n¦ +-- connect@1.7.3\r\n¦ +-- mime@1.2.4\r\n¦ +-- mkdirp@0.0.7\r\n¦ L-- qs@0.3.2\r\nL-T socket.io@0.8.7\r\n  +-- policyfile@0.0.4\r\n  +-- redis@0.6.7\r\n  L-T socket.io-client@0.8.7\r\n    +-- uglify-js@1.0.6\r\n    +-- websocket-client@1.0.0\r\n    L-- xmlhttprequest@1.2.2\r\n```\r\n\r\n### The server code:\r\n\r\n```javascript\r\nvar express = require(\"express\");\r\n\r\nvar app = express.createServer();\r\nvar io = require('socket.io').listen(app);\r\n\r\napp.use(app.router);\r\napp.use(express.static(__dirname + \"/public\"));\r\n\r\napp.get(\"/\", function(req, res) {\r\n    res.sendfile(__dirname + \"/public/dbg.html\");\r\n});\r\n\r\nvar maxUserId = 0;\r\n\r\n// This limit is here to check if desktop browser behaves the same\r\n// way. No it is not.\r\nio.set('transports', ['xhr-polling']);\r\nio.sockets.on('connection', function (socket) {\r\n    var userId = maxUserId++;\r\n    var userName = \"User \" + userId;\r\n\r\n    socket.emit('message', { text: \"You have connected\" });\r\n\r\n    socket.broadcast.emit('user-joined', {name: userName});\r\n\r\n    socket.on('disconnect', function () {\r\n        socket.broadcast.emit('user-left', {name: userName});\r\n    });\r\n});\r\n\r\napp.listen(80);\r\n```\r\n\r\n### The client code \r\ndbg.html that is served as static from the server\r\n\r\n```html\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n<meta charset=\"utf-8\" />\r\n<meta name=\"viewport\"\r\n\t  content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi\"/>\r\n\r\n<script src=\"/socket.io/socket.io.js\"></script>\r\n\r\n<script>\r\n\tfunction init() {\r\n\t\tvar socket = io.connect();\r\n\t\tsocket.on('message', function (message) {\r\n\t\t\tconsole.log(message.text);\r\n\t\t});\r\n\r\n\t\tsocket.on('user-joined', function (user) {\r\n\t\t\tconsole.log(user.name + \" joined\")\r\n\t\t});\r\n\r\n\t\tsocket.on('user-left', function (user) {\r\n\t\t\tconsole.log(user.name + \" left\");\r\n\t\t});\r\n\t}\r\n</script>\r\n</head>\r\n<body onload=\"init()\"></body>\r\n</html>\r\n```\r\n\r\n### Observed behaviour:\r\nWhen I connect to the server with the desktop browser, everything is running fine, I'm getting single \"You have connected\" message to the console, no matter how much time I leave the page opened. When I connect from the device, it reconnects as the different client all the time. So, device log is full of \"You have connected\" messages. At the same time my desktop browser is reporting that clients are connecting and disconnecting after 20 seconds:\r\n\r\n```\r\nYou have connected\r\nhttp://localhost/:18User 2 joined\r\nhttp://localhost/:22User 2 left\r\nhttp://localhost/:18User 3 joined\r\nhttp://localhost/:22User 3 left\r\nhttp://localhost/:18User 4 joined\r\n```\r\nLogcat output:\r\n\r\n```\r\n> adb.exe logcat -v raw browser:I *:S\r\n--------- beginning of /dev/log/main\r\n--------- beginning of /dev/log/system\r\nConsole: You have connected http://192.168.1.100/:14\r\nConsole: You have connected http://192.168.1.100/:14\r\nConsole: You have connected http://192.168.1.100/:14\r\nConsole: You have connected http://192.168.1.100/:14\r\nConsole: You have connected http://192.168.1.100/:14\r\n...\r\n```\r\nNote that I'm not navigating around or reloading the page... It just stays opened\r\n### My blind guess (was wrong).\r\nIt seems that android client code fails to provide the same identifier when he makes the new connection to the server. The server thinks that this is the entirely new client, and fires the \"new client\" routine. That's a blind guess. I'm trying to debug the client code now, but it is kinda slow on Android.\r\n\r\nIf someone knows how to get rid of this issue, please let me know.","assignee":null,"id":2288147,"labels":[],"number":651,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"title":"Android XHR longpoll \"reconnects\" each time","html_url":"https://github.com/LearnBoost/socket.io/issues/651","closed_at":null,"url":"https://api.github.com/repos/LearnBoost/socket.io/issues/651","milestone":null},"action":"created","comment":{"created_at":"2011-12-08T10:21:44Z","updated_at":"2011-12-08T10:21:44Z","user":{"gravatar_id":"dc2c81ae12eeeb916965bbb7e50fe30c","id":1106422,"url":"https://api.github.com/users/faeldt","avatar_url":"https://secure.gravatar.com/avatar/dc2c81ae12eeeb916965bbb7e50fe30c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"faeldt"},"body":"Thank you for your answers. I will investigate further and try to come up with something useful.","id":3060433,"url":"https://api.github.com/repos/LearnBoost/socket.io/issues/comments/3060433"}}