udpconnectsrvr.lua 533 B

12345678910111213141516
  1. local socket = require"socket"
  2. local udp = socket.udp
  3. local localhost = "127.0.0.1"
  4. local s = assert(udp())
  5. assert(tostring(s):find("udp{unconnected}"))
  6. print("setpeername", s:setpeername(localhost, 5061))
  7. print("getsockname", s:getsockname())
  8. assert(tostring(s):find("udp{connected}"))
  9. print(s:receive())
  10. print("setpeername", s:setpeername("*"))
  11. print("getsockname", s:getsockname())
  12. s:sendto("a", localhost, 12345)
  13. print("getsockname", s:getsockname())
  14. assert(tostring(s):find("udp{unconnected}"))
  15. print(s:receivefrom())
  16. s:close()