But nothing ever shows up and the client says either connection refused or timeout. Interestingly enough, the driver can send out TCP requests successfully. (this is how I handshake)
Any thoughts? I pretty much dead in the water here…
Sadly yes… I “turned if off and then back on again”.
Anyone out there have the latest firmware and working server code? It’s probably something I inadvertently took a dependency on that I shouldn’t have…
Hi, @mwilkie! It’s great to have you back in the Community.
I asked the engineering team about this and they mentioned that it’s best to use the implementation below instead of register_channel_handler because there are some issues with it that are still under analysis.
cosock.spawn(function()
local client = serversock:accept()
watch_socket(client)
end)
Probably doing something silly wrong as I’m not really a LUA guy, but here’s what I get now:
2023-01-24T18:24:01.798031866+00:00 FATAL Admin Lua: runtime error: [string "cosock.lua"]:296: [string "cosock/socket/tcp.lua"]:42: transform called on error from accept
stack traceback:
[C]: in function 'assert'
[string "cosock/socket/tcp.lua"]:42: in function <[string "cosock/socket/tcp.lua"]:41>
(...tail calls...)
[string "_myserver.lua"]:184: in function <[string "_myserver.lua"]:183>
stack traceback:
[C]: in function 'error'
[string "cosock.lua"]:296: in field 'run'
[string "st/driver.lua"]:764: in method 'run'
[string "init.lua"]:192: in main chunk
Found it, serversock:settimeout(0) is no longer valid apparently. In fact, any timeout seems to throw the error.
Regardless, using the new pattern with cosock and removing my timeout seems to have unblocked me.
Here’s what seems to be working now. If someone could check my work as I’m not 100% sure I’ve got all the right bits here, that’s be fantastic.
local function start_server(driver)
-- Startup Server
local serversock = socket.tcp()
serversock:bind('*', 0)
serversock:listen()
commonglobals.server_ip, commonglobals.server_port = serversock:getsockname()
log.info(string.format('************************** Server started at %s:%s', commonglobals.server_ip, commonglobals.server_port))
--Spawn thread to accept incoming connections
cosock.spawn(function()
while true do
local client = serversock:accept()
log.debug("Accepted connection from", client:getpeername())
handleIncoming(client)
end
end,"server loop")
end