Found example with sending datagram here: https://nim-lang.org/docs/net.html
Doing the same:
import net
var s = newSocket()
echo $s.sendTo("192.168.1.2", Port(50001), "Hello")
I have bound port on this addesss:
$ sudo netstat -tuplen | grep 50001
udp 0 0 192.168.1.2:50001 0.0.0.0:* 1000 32716323 4938/france2
Getting exception:
Traceback (most recent call last)
proto.nim(33) proto
net.nim(1444) sendTo
net.nim(1428) sendTo
SIGPIPE: Pipe closed.
I can send packets to this port using other languages. What's going wrong?
var socket = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
newSocket is default with IPPROTO_TCP
Dunno why the example is like that though.
@mashingan the documentation explicitly contains the following as an example of using UDP, which is what @luntik2012 was referring to:
var socket = newSocket()
socket.sendTo("192.168.0.1", Port(27960), "status\n")
I have submitted a PR to update the documentation: https://github.com/nim-lang/Nim/pull/8475/files