{"action":"created","issue":{"url":"https://api.github.com/repos/kernelsauce/turbo/issues/304","repository_url":"https://api.github.com/repos/kernelsauce/turbo","labels_url":"https://api.github.com/repos/kernelsauce/turbo/issues/304/labels{/name}","comments_url":"https://api.github.com/repos/kernelsauce/turbo/issues/304/comments","events_url":"https://api.github.com/repos/kernelsauce/turbo/issues/304/events","html_url":"https://github.com/kernelsauce/turbo/issues/304","id":201551451,"number":304,"title":"websocket-client recognized as 0.0.0.0 during first connect","user":{"login":"Thomas12","id":1595627,"avatar_url":"https://avatars2.githubusercontent.com/u/1595627?v=3","gravatar_id":"","url":"https://api.github.com/users/Thomas12","html_url":"https://github.com/Thomas12","followers_url":"https://api.github.com/users/Thomas12/followers","following_url":"https://api.github.com/users/Thomas12/following{/other_user}","gists_url":"https://api.github.com/users/Thomas12/gists{/gist_id}","starred_url":"https://api.github.com/users/Thomas12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Thomas12/subscriptions","organizations_url":"https://api.github.com/users/Thomas12/orgs","repos_url":"https://api.github.com/users/Thomas12/repos","events_url":"https://api.github.com/users/Thomas12/events{/privacy}","received_events_url":"https://api.github.com/users/Thomas12/received_events","type":"User","site_admin":false},"labels":[{"id":52495944,"url":"https://api.github.com/repos/kernelsauce/turbo/labels/Bug","name":"Bug","color":"e11d21","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-01-18T11:45:39Z","updated_at":"2017-03-31T10:20:46Z","closed_at":null,"body":"When a websocket client connects the first time to a turbo websocket server, the server recognizes the client IP as 0.0.0.0.\r\n\r\nI posted this problem in issue #289, but I think it got overlooked as it does not match the original topic and is a separate issue."},"comment":{"url":"https://api.github.com/repos/kernelsauce/turbo/issues/comments/290675991","html_url":"https://github.com/kernelsauce/turbo/issues/304#issuecomment-290675991","issue_url":"https://api.github.com/repos/kernelsauce/turbo/issues/304","id":290675991,"user":{"login":"Thomas12","id":1595627,"avatar_url":"https://avatars2.githubusercontent.com/u/1595627?v=3","gravatar_id":"","url":"https://api.github.com/users/Thomas12","html_url":"https://github.com/Thomas12","followers_url":"https://api.github.com/users/Thomas12/followers","following_url":"https://api.github.com/users/Thomas12/following{/other_user}","gists_url":"https://api.github.com/users/Thomas12/gists{/gist_id}","starred_url":"https://api.github.com/users/Thomas12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Thomas12/subscriptions","organizations_url":"https://api.github.com/users/Thomas12/orgs","repos_url":"https://api.github.com/users/Thomas12/repos","events_url":"https://api.github.com/users/Thomas12/events{/privacy}","received_events_url":"https://api.github.com/users/Thomas12/received_events","type":"User","site_admin":false},"created_at":"2017-03-31T10:20:46Z","updated_at":"2017-03-31T10:20:46Z","body":"Yes, sure, see below:\r\n1. Start server\r\n2. Connect with client\r\n3. see in server: client identified as 0.0.0.0\r\n\r\n(Tried putting the code in `` for nicer layout, but that's not recognized).\r\n\r\nServer:\r\n##########\r\n_G.TURBO_SSL = true\r\nlocal turbo = require \"turbo\"\r\n\r\nlocal socks = {}\r\nlocal io_loop = turbo.ioloop.instance()\r\n\r\nlocal WSExHandler = class(\"WSExHandler\", turbo.websocket.WebSocketHandler)\r\n\r\n\r\nfunction WSExHandler:open(msg)\r\n    self:write_message(\"Hello you.\")\r\n    socks[self] = self\r\nend\r\n\r\nfunction WSExHandler:on_close()\r\n    socks[self] = nil\r\nend\r\n\r\n\r\nfunction WSExHandler:on_error(msg)\r\n    socks[self] = nil\r\n    print(\"Error: \" .. msg)\r\nend\r\n\r\n\r\nAppHandler = class(\"AppHandler\", turbo.web.RequestHandler)\r\n\r\nfunction AppHandler:get(url)\r\n self:write(\"Hi!\")\r\n return\r\nend\r\n\r\n\r\nturbo.web.Application({{\"^/ws$\", WSExHandler}, {\"^/$\", AppHandler} }):listen(80)\r\n\r\n j=0\r\n io_loop:set_interval(1000, function()\r\n j=j+1\r\n if(j%10==0) then\r\n   io_loop:add_callback(get)\r\n end\r\n\r\n for _, sock in pairs(socks) do\r\n   sock.counter = sock.counter and (sock.counter+1) or 0\r\n   sock:write_message(\"Still alive. Counting: \" .. tostring(sock.counter))\r\n end\r\nend)\r\n\r\n\r\nfunction get()\r\n    -- Must place everything in a IOLoop callback.\r\n    local res = coroutine.yield(\r\n        turbo.async.HTTPClient():fetch(\"http://www.google.com/\",\r\n            {allow_redirects=true, connect_timeout=15}))\r\n    if res.error or res.headers:get_status_code() ~= 200 then\r\n        -- Check for errors.\r\n        print(\"Could not get URL:\", res.error.message)\r\n    else\r\n        -- Print result to stdout.\r\n        io.write(res.body)\r\n    end\r\nend\r\n\r\nio_loop:add_callback(get)\r\n\r\n\r\nfunction turbo.log.error(str)\r\n last_error=str\r\n print(\"ERROR: \"..str)\r\n return\r\nend\r\n\r\nio_loop:start()\r\n\r\n\r\n\r\n\r\nClient:\r\n#######\r\n\r\n_G.TURBO_SSL = true -- SSL must be enabled for WebSocket support!\r\nlocal turbo = require \"turbo\"\r\n\r\nturbo.ioloop.instance():add_callback(function()\r\n    turbo.websocket.WebSocketClient(\"ws://127.0.0.1:80/ws\", {\r\n        on_message = function(self, msg)\r\n            -- Print the incoming message.\r\n            print(msg)\r\n        end,\r\n        on_close = function(self)\r\n            -- I am called when connection is closed. Both gracefully and\r\n            -- not gracefully.\r\n            os.exit(0)\r\n        end,\r\n        on_error = function(self, code, reason)\r\n            print(code, reason)\r\n            os.exit(1)\r\n        end\r\n    })\r\nend):start()\r\n\r\n"}}
{"actor":{"display_login":"Thomas12"}}