This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
worqy's profile picture

rednet help

Started by worqy, 20 May 2012 - 08:41 AM
worqy #1
Posted 20 May 2012 - 10:41 AM
Hi

I'm trying to create chat program with a client and a server.

I need help figuring out how to check for incoming messages and be able to write a message at the same time.
When I do rednet.receive() it wont let me write something that I could send to the server.

Here is the code:
Client


rednet.open("right")
rednet.receive()
read()

function send(msg)
rednet.broadcast(msg)
end

function read()
while true do
message = io.read()
send(message)
end
end

Server


rednet.open("right")
print("Server online")
rednet.broadcast("Connect to server with ID #2")
rednet.receive()
read()

function send(msg)
rednet.broadcast(msg)
end

function read()
while true do
message = io.read()
send(message)
end
end
MysticT #2
Posted 20 May 2012 - 07:45 PM
You could handle the "rednet_message", "key" and "char" events to get the input and the messages. It would require you to handle the input yourself (you can't use read()). An alternative would be using the parallel api to run both functions at the same time, but it might make a mess in the screen if you don't move the cursor for each function to different places.