fix(net): bad channel + change return of sendQuery
This commit is contained in:
parent
5305afe203
commit
4f16cef9f5
11
libs/net.lua
11
libs/net.lua
@ -13,21 +13,20 @@ end
|
||||
net.listenQuery = function(hostname, processQueryMessage)
|
||||
assertRednetIsOpened()
|
||||
|
||||
rednet.host(QUERY_PROTO, hostname)
|
||||
|
||||
local serverRunning = true
|
||||
|
||||
local function stopServer()
|
||||
serverRunning = false
|
||||
end
|
||||
|
||||
rednet.host(QUERY_PROTO, hostname)
|
||||
|
||||
while serverRunning do
|
||||
local computerId, message = rednet.receive(QUERY_PROTO)
|
||||
local responseMessage = processQueryMessage(textutils.unserialize(message), computerId, stopServer)
|
||||
rednet.send(computerId, textutils.serialize(responseMessage), QUERY_RESPONSE_PROTO)
|
||||
end
|
||||
|
||||
-- in case we decide to exit the loop in the future
|
||||
rednet.unhost(QUERY_PROTO)
|
||||
end
|
||||
|
||||
@ -38,19 +37,19 @@ net.sendQuery = function(hostname, message, timeout)
|
||||
local serverId = rednet.lookup(QUERY_PROTO, hostname)
|
||||
|
||||
if not serverId then
|
||||
return false, 'hostname lookup error'
|
||||
return nil, 'hostname lookup error'
|
||||
end
|
||||
|
||||
local sendOk = rednet.send(serverId, textutils.serialize(message))
|
||||
|
||||
if not sendOk then
|
||||
return false, 'rednet error'
|
||||
return nil, 'rednet error'
|
||||
end
|
||||
|
||||
local responseServerId, responseMessage = rednet.receive(QUERY_RESPONSE_PROTO, timeout)
|
||||
|
||||
if not responseServerId then
|
||||
return false, 'timeout'
|
||||
return nil, 'timeout'
|
||||
end
|
||||
|
||||
return textutils.unserialize(responseMessage)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user