From 0ca4b6ba55d2b7013e2b081866a01907026d00a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Wed, 1 Feb 2017 20:59:43 +0100 Subject: [PATCH] Add more UDP documentation, contributes to #1701 --- docs/en/modules/net.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/en/modules/net.md b/docs/en/modules/net.md index 17f4e023..58a425d0 100644 --- a/docs/en/modules/net.md +++ b/docs/en/modules/net.md @@ -451,6 +451,35 @@ The syntax and functional similar to [`net.socket:on()`](#netsocketon). However, Sends data to specific remote peer. +#### Syntax +`send(port, ip, data)` + +#### Parameters +- `port` remote socket port +- `ip` remote socket IP +- `data` the payload to send + +#### Returns +`nil` + +#### Example +```lua +udpSocket = net.createUDPSocket() +udpSocket:listen(5000) +udpSocket:on("receive", function(s, data, port, ip) + print(string.format("received '%s' from %s:%d", data, ip, port)) + s:send(port, ip, "echo: " .. data) +end) +port, ip = udpSocket:getaddr() +print(string.format("local UDP socket address / port: %s:%d", ip, port)) +``` +On *nix systems that can then be tested by issuing + +``` +echo -n "foo" | nc -w1 -u 5000 +``` + + ## net.udpsocket:dns() Provides DNS resolution for a hostname.