Posted 15 April 2012 - 11:44 PM
I want my client software and server software to "shake hands" before continuing and sending messages. How would I allow a computer to be working normally and when it recieves a rednet message to see if its equal to a certain piece of text and then start passing data to it?
Heres my code so far,
Client
Heres my code so far,
Client
rednet.open("right")
rednet.open("left")
rednet.open("bottom")
rednet.open("top")
rednet.open("back")
rednet.open("front")
local ip = os.computerID()
local serverip = "";
local user = "";
function connect()
print("Connecting user: "..user.." to server "..serverip)
rednet.broadcast("ping")
id, message = rednet.receive(5)
if message == "handshake" then
print("Hand shake successful, loading data from server")
else
print("Hand shake failed, please check your server id and try again")
sleep(1)
login()
end
end
function login()
print("Welcome to the Chat Network")
print("Please enter your nick")
nick = read()
print("Please enter the ID of the server you wish to connect to")
serv = read()
user = nick
serverip = serv
connect()
end
login()
Server
rednet.open("right")
rednet.open("left")
rednet.open("bottom")
rednet.open("top")
rednet.open("back")
rednet.open("front")
local ip = os.computerID()
local serverip = "";
local user = "";
function connect()
local ping,p2,p3 = os.pullEvent()
id, message = rednet.receive()
print("Connections enabled")
print(ping)
print(p2)
print(p3)
end
connect()
I also want to be able to use the variable serverip in the rednet.send command, but that does not work as it returns "Rednet expected a positive number"