turbo icon indicating copy to clipboard operation
turbo copied to clipboard

websocket-client recognized as 0.0.0.0 during first connect

Open Thomas12 opened this issue 8 years ago • 4 comments

When a websocket client connects the first time to a turbo websocket server, the server recognizes the client IP as 0.0.0.0.

I 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.

Thomas12 avatar Jan 18 '17 11:01 Thomas12

I know about it, but due very little time available for free software at the moment I haven't had the time to look at this. I will eventually get at it, but I would also accept any merge requests for this issue ;).

kernelsauce avatar Jan 18 '17 11:01 kernelsauce

I just want to kindly ask if you please could find the time to solve these 2 issues:

  1. 0.0.0.0 ip
  2. include SNI for https (I have provided the needed components in #274)

Thank you very much!

Thomas

Thomas12 avatar Mar 19 '17 13:03 Thomas12

Can you provide some example code to reproduce the 0.0.0.0 issue @Thomas12 ?

kernelsauce avatar Mar 31 '17 10:03 kernelsauce

Yes, sure, see below:

  1. Start server
  2. Connect with client
  3. see in server: client identified as 0.0.0.0

(Tried putting the code in `` for nicer layout, but that's not recognized).

Server: ########## _G.TURBO_SSL = true local turbo = require "turbo"

local socks = {} local io_loop = turbo.ioloop.instance()

local WSExHandler = class("WSExHandler", turbo.websocket.WebSocketHandler)

function WSExHandler:open(msg) self:write_message("Hello you.") socks[self] = self end

function WSExHandler:on_close() socks[self] = nil end

function WSExHandler:on_error(msg) socks[self] = nil print("Error: " .. msg) end

AppHandler = class("AppHandler", turbo.web.RequestHandler)

function AppHandler:get(url) self:write("Hi!") return end

turbo.web.Application({{"^/ws$", WSExHandler}, {"^/$", AppHandler} }):listen(80)

j=0 io_loop:set_interval(1000, function() j=j+1 if(j%10==0) then io_loop:add_callback(get) end

for _, sock in pairs(socks) do sock.counter = sock.counter and (sock.counter+1) or 0 sock:write_message("Still alive. Counting: " .. tostring(sock.counter)) end end)

function get() -- Must place everything in a IOLoop callback. local res = coroutine.yield( turbo.async.HTTPClient():fetch("http://www.google.com/", {allow_redirects=true, connect_timeout=15})) if res.error or res.headers:get_status_code() ~= 200 then -- Check for errors. print("Could not get URL:", res.error.message) else -- Print result to stdout. io.write(res.body) end end

io_loop:add_callback(get)

function turbo.log.error(str) last_error=str print("ERROR: "..str) return end

io_loop:start()

Client: #######

_G.TURBO_SSL = true -- SSL must be enabled for WebSocket support! local turbo = require "turbo"

turbo.ioloop.instance():add_callback(function() turbo.websocket.WebSocketClient("ws://127.0.0.1:80/ws", { on_message = function(self, msg) -- Print the incoming message. print(msg) end, on_close = function(self) -- I am called when connection is closed. Both gracefully and -- not gracefully. os.exit(0) end, on_error = function(self, code, reason) print(code, reason) os.exit(1) end }) end):start()

Thomas12 avatar Mar 31 '17 10:03 Thomas12