krzys_h

Chat v1.0

Aug 16th, 2012
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. function odbieraj()
  2.  while true do
  3.   id, msg = rednet.receive()
  4.   print(id .. "> " .. msg)
  5.   if msg == "/ping" then
  6.    rednet.send(id, "/pong")
  7.    print(os.getComputerID() .. "> /pong")
  8.    print("**> " .. id .. " podlaczony!")
  9.   end
  10.  end
  11. end
  12.  
  13. function wysylaj()
  14.  while true do
  15.   input = read()
  16.   rednet.broadcast(input)
  17.   if input == "/exit" then
  18.    return
  19.   end
  20.  end
  21. end
  22.  
  23. print("Witaj na Chacie!")
  24. rednet.open("top")
  25. print("Wpisz /exit aby wyjsc")
  26. rednet.broadcast("/ping")
  27. write("Podlaczeni: " .. os.getComputerID())
  28. while true do
  29.  id, msg = rednet.receive(1)
  30.  if msg == nil then
  31.   print(".")
  32.   break
  33.  end
  34.  if msg == "/pong" then
  35.   write(", " .. id)
  36.  end
  37. end
  38. parallel.waitForAny(odbieraj, wysylaj)
  39. print("Do zobaczenia")
Advertisement
Add Comment
Please, Sign In to add comment