udpconnectclnt.lua 611 B

12345678910111213141516171819
  1. local socket = require"socket"
  2. local udp = socket.udp
  3. local localhost = "127.0.0.1"
  4. local port = assert(arg[1], "missing port argument")
  5. se = udp(); se:setoption("reuseaddr", true)
  6. se:setsockname(localhost, 5062)
  7. print("se", se:getsockname())
  8. sc = udp(); sc:setoption("reuseaddr", true)
  9. sc:setsockname(localhost, 5061)
  10. print("sc", sc:getsockname())
  11. se:sendto("this is a test from se", localhost, port)
  12. socket.sleep(1)
  13. sc:sendto("this is a test from sc", localhost, port)
  14. socket.sleep(1)
  15. se:sendto("this is a test from se", localhost, port)
  16. socket.sleep(1)
  17. sc:sendto("this is a test from sc", localhost, port)