Example of a simply UDP client

2020-12-02 Thread JohnAD
Thank you so much! Binding to the port is fine (and needed for client to get past the NAT routers that 99% of end-users sit behind). But binding to a specific address, such as the loopback/localhost (127.0.0.1) forces it to an interface that has no route to the destination address. Makes sense.

Example of a simply UDP client

2020-11-30 Thread mashingan
> But, if I set the address to 192.168.1.45, > > socket.bindAddr(Port(cfgPort), localhost) This is the problem, change it to empty string which set it to `ADDR_ANY` in order the bound address able to listen to any address e.g. socket.bindAddr(Port cfgPort) Run Just f

Example of a simply UDP client

2020-11-30 Thread elcritch
Expanding on the selector method, I made a "wrapper" for tcp sockets, originally to help with multi-plexing serial/uart data on embedded /esp32. Async still gives me a headache so I like selectors. It should be very similar to UDP handling.

Example of a simply UDP client

2020-11-30 Thread elcritch
Not sure, but the async version shouldn't be using the selector anymore. Essentially the async will use selectors internally to dispatch the async when data is ready. However, your async version also looks like you're reusing the same socket for both local and remote clients. At least with TCP,

Example of a simply UDP client

2020-11-29 Thread JohnAD
On the off change that @dom96's advice to use async was part of the problem. I converted it to async: import asyncdispatch, asyncnet import std/[net, selectors, strformat, strutils] const cfgMaxPacket = 500 clientPort = 8800 clientHost = "127.0.0.1"

Example of a simply UDP client

2020-11-29 Thread JohnAD
Anyone know why I cant seem to use `sendTo` for an off-machine address? Using @jrfonden 's example above, if I set the `sendTo` address to `192.168.1.44` which is the machine I'm on, it works just fine. (Especially if I'm also running the UDP server on my local machine.) But, if I set the addre

Example of a simply UDP client

2020-11-23 Thread dom96
@jrfondren This is brilliant, but please never do `cast[int](socket.getFd)`, you should instead use the safe casting: `socket.getFd().int` (`cast` will do whatever you tell it, including converting types that don't make sense which can cause memory corruption). Also, consider using `asyncnet`'s

Example of a simply UDP client

2020-11-22 Thread jrfondren
Sending and receiving UDP while accepting stdin, with just selectors: import std/[net, selectors, strformat, strutils] const cfgMaxPacket = 500 cfgPort = 8800 localhost = "127.0.0.1" let socket = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)

Example of a simply UDP client

2020-11-22 Thread enthus1ast
since recently there is also async udp functionallity. So no need using useing threads

Example of a simply UDP client

2020-11-22 Thread JohnAD
Reading a string from the terminal is easy. Receiving a UDP packet is easy and there are ready examples. Sending a UDP packet is really easy. So SURELY doing all three at once is also easy I just spent many days on working out different ways to do that. Fortunately since UDP is connectionl