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

Error Simple Network

Started by duncandelano, 04 October 2012 - 03:01 PM
duncandelano #1
Posted 04 October 2012 - 05:01 PM
I made this new program with a client and a server, now when i ping the server from the client i get a ping back. but when i try to ping the seconed time, it doesnt work.

Server Code:

rednet.open("top")
stop=0
while true do
  local event,p1,p2,p3 = os.pullEvent()
  if event=="rednet_message" then
   if p2=="$PING" then
    print("Computer: "..p1.." Send a Pong request")
    p1=sender
    rednet.send(sender, "pong")
    wait=0
    while wait==0 do
	 local event,p1,p2,p3 = os.pullEvent()
	  if p2=="$GOT" then do
	   print("Request succesfull")
	  end
	 end
    end
   
   else
    print("I Received a Message!")
    print("From: "..p1.." Computer")
    print("Message: "..p2.."")
    print("The Distance to Computer "..p1.." is "..p3.." Blocks")
   end
 
  end
end


The client:



print("Please input master server ID")
masterserver1 = tonumber(read())
rednet.send(masterserver1, "$PING")
x=0
while x==0 do
  rednet.send(masterserver1, "$PING")
  local event,p1,p2,p3 = os.pullEvent()
  if event=="rednet_message" then
   rednet.send(29, "$GOT")
   print(""..p1.."")
   print(""..p2.."")
   x=1
  end
end

  
Mtdj2 #2
Posted 04 October 2012 - 05:13 PM
First, at the server code, p1 = sender should be sender = p1.
Second, at line 16 you got an end too much.
Then the client, you are sending a $ping too much.
Also, you can replace the os.pullEvent() with IAmATable = rednet.receive(). It is important that IAmATable is defined like IAmATable = {} before using the rednet.receive() thing.
I hope I helped.
duncandelano #3
Posted 04 October 2012 - 05:37 PM
Tanks for the help but i still cant get it to work, the table stuff i tried but doesnt seem to work because it doesnt give ANY output. end when i remove an end it says that its exepcting an end at line 19 to close while at line 11. :(/>/>.