3 local socket = require "socket"
5 local uloop = require("uloop")
8 local udp = socket.udp()
10 udp:setsockname('*', 8080)
15 print("1000 ms timer run");
18 timer = uloop.timer(t)
22 uloop.timer(function() print("2000 ms timer run"); end, 2000)
25 uloop.timer(function() print("3000 ms timer run"); end, 3000):cancel()
29 print("Process 1 completed")
34 print("Process 2 completed")
40 uloop.process("uloop_pid_test.sh", {"foo", "bar"}, {"PROCESS=1"}, p1)
45 uloop.process("uloop_pid_test.sh", {"foo", "bar"}, {"PROCESS=2"}, p2)
49 udp_ev = uloop.fd_add(udp, function(ufd, events)
50 local words, msg_or_ip, port_or_nil = ufd:receivefrom()
51 print('Recv UDP packet from '..msg_or_ip..':'..port_or_nil..' : '..words)
52 if words == "Stop!" then
55 end, uloop.ULOOP_READ)
58 udp_send_timer = uloop.timer(
60 local s = socket.udp()
64 udp_send_timer:cancel()
67 udp_send_timer:set(1000)
69 print('Send UDP packet to 127.0.0.1:8080 :'..words)
70 s:sendto(words, '127.0.0.1', 8080)
73 udp_count = udp_count + 1