client.lua 459 B

123456789101112131415161718192021222324252627282930
  1. require "enet"
  2. local host = enet.host_create()
  3. local server = host:connect("localhost:5678")
  4. local count = 0
  5. while count < 100 do
  6. local event = host:service(100)
  7. if event then
  8. if event.type == "receive" then
  9. print("Got message: ", event.data)
  10. else
  11. print("Got event", event.type)
  12. end
  13. end
  14. if count == 8 then
  15. print "sending message"
  16. server:send("hello world")
  17. end
  18. count = count + 1
  19. end
  20. server:disconnect()
  21. host:flush()
  22. print"done"