Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket-client recognized as 0.0.0.0 during first connect #304

Open
Thomas12 opened this issue Jan 18, 2017 · 4 comments
Open

websocket-client recognized as 0.0.0.0 during first connect #304

Thomas12 opened this issue Jan 18, 2017 · 4 comments
Labels

Comments

@Thomas12
Copy link

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.

@kernelsauce
Copy link
Owner

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 ;).

@Thomas12
Copy link
Author

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 Please implement Server Name Indication (SNI) for async.HTTPClient #274)

Thank you very much!

Thomas

@kernelsauce
Copy link
Owner

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

@Thomas12
Copy link
Author

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants