diff options
Diffstat (limited to 'samples/echoclnt.lua')
| -rw-r--r-- | samples/echoclnt.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/samples/echoclnt.lua b/samples/echoclnt.lua new file mode 100644 index 0000000..d1c56c7 --- /dev/null +++ b/samples/echoclnt.lua | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | host = host or "localhost" | ||
| 2 | port = port or 7 | ||
| 3 | if arg then | ||
| 4 | host = arg[1] or host | ||
| 5 | port = arg[2] or port | ||
| 6 | end | ||
| 7 | host = toip(host) | ||
| 8 | udp, err = udpsocket() | ||
| 9 | if not udp then print(err) exit() end | ||
| 10 | err = setpeername(udp, host, port) | ||
| 11 | if err then print(err) exit() end | ||
| 12 | print("Using host '" ..host.. "' and port " ..port.. "...") | ||
| 13 | while 1 do | ||
| 14 | line = read() | ||
| 15 | if not line then exit() end | ||
| 16 | err = send(udp, line) | ||
| 17 | if err then print(err) exit() end | ||
| 18 | dgram, err = receive(udp) | ||
| 19 | if not dgram then print(err) exit() end | ||
| 20 | print(dgram) | ||
| 21 | end | ||
