server.lua 431 B

12345678910111213141516171819
  1. require "enet"
  2. local host = enet.host_create"localhost:5678"
  3. while true do
  4. local event = host:service(100)
  5. if event then
  6. if event.type == "receive" then
  7. print("Got message: ", event.data, event.peer)
  8. event.peer:send("howdy back at ya")
  9. elseif event.type == "connect" then
  10. print("Connect:", event.peer)
  11. host:broadcast("new client connected")
  12. else
  13. print("Got event", event.type, event.peer)
  14. end
  15. end
  16. end