{"action":"created","issue":{"url":"https://api.github.com/repos/rikulo/socket.io-client-dart/issues/2","repository_url":"https://api.github.com/repos/rikulo/socket.io-client-dart","labels_url":"https://api.github.com/repos/rikulo/socket.io-client-dart/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/rikulo/socket.io-client-dart/issues/2/comments","events_url":"https://api.github.com/repos/rikulo/socket.io-client-dart/issues/2/events","html_url":"https://github.com/rikulo/socket.io-client-dart/issues/2","id":245421484,"number":2,"title":"Socket not working when I do a pub build","user":{"login":"smrtsmrf","id":17756776,"avatar_url":"https://avatars3.githubusercontent.com/u/17756776?v=4","gravatar_id":"","url":"https://api.github.com/users/smrtsmrf","html_url":"https://github.com/smrtsmrf","followers_url":"https://api.github.com/users/smrtsmrf/followers","following_url":"https://api.github.com/users/smrtsmrf/following{/other_user}","gists_url":"https://api.github.com/users/smrtsmrf/gists{/gist_id}","starred_url":"https://api.github.com/users/smrtsmrf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smrtsmrf/subscriptions","organizations_url":"https://api.github.com/users/smrtsmrf/orgs","repos_url":"https://api.github.com/users/smrtsmrf/repos","events_url":"https://api.github.com/users/smrtsmrf/events{/privacy}","received_events_url":"https://api.github.com/users/smrtsmrf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-07-25T14:31:23Z","updated_at":"2018-02-01T16:31:43Z","closed_at":null,"author_association":"NONE","body":"I've got the socket working when I have my client files running on pub serve through Webstorm. (Although the connection is sometimes finnicky.)\r\n\r\nBut when I do a pub build so that I can serve up the files from my server, the socket doesn't seem to work at all. \r\n\r\nHere's my (relevant) dart client code:\r\n\r\n```\r\nvoid ngOnInit() {\r\n    name = _routeParams.get('name');\r\n    socket = IO.io('http://localhost:3000');\r\n    socket.connect();\r\n    socket.on('connect', (_) {\r\n      print('Socket connected (client)');\r\n      // need to send something stupid initially so that it will keep listening\r\n      socket.emit('client', 1);\r\n\r\n      socket.on('server', (_) => print('handshake'));\r\n      \r\n      countDownTimer = new Timer.periodic(const Duration(seconds: 1), (Timer countDownTimer) {\r\n        countDown--;\r\n        timerMsg = countDown > 0 ? 'BEGIN IN ${countDown}' : 'GO!';\r\n\r\n        if (countDown == 0) {\r\n          socket.emit('start game', 2);\r\n          countDownTimer.cancel();\r\n          gameInProgress = true;\r\n          \r\n          gameTimer = new Timer.periodic(const Duration(seconds: 1), (Timer gameTimer) {\r\n            gameTime--;\r\n            gameTimerMsg = gameTime > 0 ? gameTime.toString() : 'END GAME';\r\n\r\n            if (gameTime == 0) {\r\n              print('game over');\r\n\r\n              \r\n              print('updateLeaderboard');\r\n              Leader player = new Leader(name, 25);\r\n              _leaderboardService.leaders.add(player);\r\n              _leaderboardService.leaders.sort((a, b) => b.score.compareTo(a.score));\r\n              print('about to end game');\r\n              socket.emit('end game', 'i am a string');\r\n              print('should have ended game');\r\n              gameTimer.cancel();\r\n              this._router.navigate(['Leaderboard', player.toMap()]);\r\n            }\r\n          });\r\n        }\r\n      });\r\n    });\r\n\r\n    socket.on('new color', (data) {\r\n      print('new color: $data');\r\n      HTML.Animation animation;\r\n      HTML.Element element;\r\n      switch (data) {\r\n        case 1:\r\n          element = green.nativeElement; break;\r\n        case 2:\r\n          element = red.nativeElement; break;\r\n        case 3:\r\n          element = yellow.nativeElement; break;\r\n        case 4:\r\n          element = blue.nativeElement; break;\r\n      }\r\n      animation = element.animate([{\"opacity\": 100}, {\"opacity\": 0}], 150);\r\n      animation.play();\r\n    });\r\n\r\n    socket.on('point', (_) => score++);\r\n    \r\n    socket.on('ended game', (_) {\r\n      socket.clearListeners();\r\n      socket.disconnect();\r\n    });\r\n\r\n    socket.on('disconnected', (_) => print('socket disconnected (server)'));\r\n  \r\n}\r\n```\r\n\r\nAnd here's the errors I'm getting in Chrome:\r\n![screen shot 2017-07-25 at 8 27 15 am](https://user-images.githubusercontent.com/17756776/28577307-a07b0436-7113-11e7-82db-8edcf1e2f4da.png)\r\n"},"comment":{"url":"https://api.github.com/repos/rikulo/socket.io-client-dart/issues/comments/362321888","html_url":"https://github.com/rikulo/socket.io-client-dart/issues/2#issuecomment-362321888","issue_url":"https://api.github.com/repos/rikulo/socket.io-client-dart/issues/2","id":362321888,"user":{"login":"NickWu007","id":17936144,"avatar_url":"https://avatars2.githubusercontent.com/u/17936144?v=4","gravatar_id":"","url":"https://api.github.com/users/NickWu007","html_url":"https://github.com/NickWu007","followers_url":"https://api.github.com/users/NickWu007/followers","following_url":"https://api.github.com/users/NickWu007/following{/other_user}","gists_url":"https://api.github.com/users/NickWu007/gists{/gist_id}","starred_url":"https://api.github.com/users/NickWu007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NickWu007/subscriptions","organizations_url":"https://api.github.com/users/NickWu007/orgs","repos_url":"https://api.github.com/users/NickWu007/repos","events_url":"https://api.github.com/users/NickWu007/events{/privacy}","received_events_url":"https://api.github.com/users/NickWu007/received_events","type":"User","site_admin":false},"created_at":"2018-02-01T16:31:43Z","updated_at":"2018-02-01T16:31:43Z","author_association":"NONE","body":"Hi,\r\n\r\nI have been having the same problem, but slightly different.\r\n\r\nOn `pub serve` things are working fine, but on `pub build`, locally I would get a few 400 errors but eventually succeed to connect. Below is a screenshot:\r\n\r\n![screen shot 2018-02-01 at 16 24 04](https://user-images.githubusercontent.com/17936144/35689869-63d75648-076c-11e8-9d2f-7a6636a44a4c.png)\r\n\r\nI am also deploying my app on digital ocean VPS and over there I would get a huge number of 400 errors(with same response body), and finally connect after 1 or 2 minutes. Below is a screenshot of network activities on VPS.\r\n\r\n![screen shot 2018-01-30 at 20 53 21](https://user-images.githubusercontent.com/17936144/35689966-a78784c6-076c-11e8-8394-7be60507ba13.png)\r\n![screen shot 2018-01-30 at 20 56 02](https://user-images.githubusercontent.com/17936144/35689967-a7a62d22-076c-11e8-8d06-0a6c3edc6cb6.png)\r\n\r\nMy server is written in node:\r\n\r\n```\r\nvar app = express()\r\nvar server = http.createServer(app);\r\nserver.listen(port);\r\nvar io = require('socket.io').listen(server);\r\n```\r\n\r\nI am using namespaces also, for each client:\r\n\r\n```\r\nvar socketPath = '/' + req.session.user.username\r\nio.of(socketPath).on('connection', function (socket) {\r\n    ...\r\n}\r\n```\r\n\r\nClient:\r\n\r\n```\r\nString namespace = 'http://localhost:5000' + socketPath;\r\nprint('connecting to $namespace');\r\nsocket = IO.io(namespace);\r\nsocket.on('connect', (_) {\r\n        print('connected to $namespace');\r\n        ....\r\n}\r\n```\r\n\r\nAs far as I can see there's very little custom config used. Could you please take a look as this? I can discuss more in detail. This lib is critical for my project, so please help.\r\n\r\nThanks,\r\nNick"}}
{"actor":{"display_login":"NickWu007"}}