camchenry / sock.lua

A Lua networking library for LÖVE games.
https://camchenry.github.io/sock.lua/
MIT License
173 stars 7 forks source link

Client:connect() does not return anything #3

Open thebenign opened 7 years ago

thebenign commented 7 years ago

The documentation states that Client:connect() will return a boolean value indicating whether the connection was successful or not. It currently returns nil in every case.

camchenry commented 7 years ago

You're right, and the documentation has been corrected in some of the more recent updates. (Which will come soon!) The actual connection event doesn't occur until the next time the client and server are updated. So, there's no way to tell if a connection succeeded at the time the connect method is called.

thebenign commented 7 years ago

Thanks for the reply! I did notice that when I looked through the code. It makes sense with how enet handles peer creation / connection. Do you plan to implement this feature some other way?

camchenry commented 7 years ago

For now, you can just set some connected state when the "connect" event goes off.

-- client code
connected = false

client:connect()

client:on("connect", function()
    connected = true
end)