Remember that if a computer is in an unloaded chunk, it'll shut down (then restart itself when the chunk next loads again).
The main problem I see here is that your print calls can potentially go off while you're busy typing stuff for your read calls. There are a number of ways to deal with this, but assuming you're on CC 1.6 or later, the simplest is probably the
window API. It allows you to divide up your screen into multiple "displays", so you can work in one without worrying too much about what's happening in the other (by
redirecting ComputerCraft's terminal output between the two of them).
The code might look a little something like this:
rednet.open("left")
local xSize, ySize = term.getSize() -- Get the size of the whole display.
local incoming = window.create(term.current(), 1, 1, xSize, ySize - 2) -- A window covering the whole screen minus the last two lines.
local outgoing = window.create(term.current(), 1, ySize, xSize, 1) -- A window covering just the last line of the screen.
-- Draw a dividing line between the two windows:
term.setCursorPos(1,ySize - 1)
term.write(string.rep("-", xSize))
local function receive()
while true do
local id, ms = rednet.receive()
if id ~= os.getComputerID() and type(ms) == "string" then
term.redirect(incoming) -- The larger window is now our "screen".
print("["..id.."] "..msg)
term.redirect(outgoing) -- The one-line window down the bottom of the display is now our "screen".
end
end
end
local function send()
while true do
term.setCursorPos(1,1)
rednet.broadcast(read())
end
end
term.redirect(outgoing) -- The one-line window down the bottom of the display is now our "screen".
parallel.waitForAny(receive, send) -- No need to loop this; the functions already loop themselves.