Posted 29 May 2015 - 03:53 PM
So, I have a server, there will be many clients.
The server sends out a message rapidly (this will be set to 5 seconds)
the client will respond to that message.
Its supposed to be set where if you break the client that the server will spit out that the computer has been broken in red text, if you place the client back down, it wont reply because it had already pinged and its waiting for the rednet message, I could have a while loop running and it would break when it received a message, but then how would you tell if the client has been broken or "hacked," have a timer that counts down 10 seconds?
I have the server printing to a monitor on top whether the ping was sucessful or not.
The color changes between green and lime so you can easily see the difference if the program is running or got stuck on pinging.
My setup:
Server Code:
The client code:
Yes, I know that the setTextColor should be outside the loop, but i used to print out other things and it had to keep setting the color back to orange, this could had been handled in a function but for some reason I didn't do that :P/>
The server sends out a message rapidly (this will be set to 5 seconds)
the client will respond to that message.
Its supposed to be set where if you break the client that the server will spit out that the computer has been broken in red text, if you place the client back down, it wont reply because it had already pinged and its waiting for the rednet message, I could have a while loop running and it would break when it received a message, but then how would you tell if the client has been broken or "hacked," have a timer that counts down 10 seconds?
I have the server printing to a monitor on top whether the ping was sucessful or not.
The color changes between green and lime so you can easily see the difference if the program is running or got stuck on pinging.
My setup:
Server Code:
color = colors.lime
monitor = peripheral.wrap("top")
modem_side = "back"
monitor_or_terminal = "monitor"
rednet.open(modem_side)
if monitor_or_terminal == "monitor" then
term.redirect(monitor)
end
while true do
term.setTextColor(colors.magenta)
print("Pinging Client 1")
rednet.broadcast("C1:PING")
event, id, message = os.pullEvent("rednet_message")
--print(event.." "..id.." "..message)
if message ~= nil then
if message == "C1 RETURN PING" then
term.setTextColor(color)
print("Client:1:Stable:ReturnPing")
end
else
term.setTextColor(colors.red)
print("No message recieved, client 1 crashed or hacked")
end
if color == colors.green then
color = colors.lime
elseif color == colors.lime then
color = colors.green
end
sleep(0.1)
end
The client code:
rednet.open("top")
while true do
event, id, message = os.pullEvent("rednet_message")
if message == "C1:PING" then
term.setTextColor(colors.orange)
print("Recieved message from server, responding ping request")
rednet.broadcast("C1 RETURN PING")
end
end
Yes, I know that the setTextColor should be outside the loop, but i used to print out other things and it had to keep setting the color back to orange, this could had been handled in a function but for some reason I didn't do that :P/>
Edited on 29 May 2015 - 02:03 PM