> 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 for completion, this is my code
# sender.nim
import net, strutils
const
# this is the address in the same network but different machine and ip
foreignAddr = "192.168.18.62"
foreignPort = Port 9999
var socket = newSocket(sockType = SOCK_DGRAM, protocol = IPPROTO_UDP)
var running = true
while running:
let msg = stdin.readLine
socket.sendTo(foreignAddr, foreignPort, msg & "\c\L")
if msg.toLowerAscii == "quit":
running = false
Run
and this is the receiver
#receiver.nim
import net, asyncnet, strutils, asyncdispatch
const withSize = 256 # each datagram size
var running = true
var socket = newAsyncSocket(sockType = SOCK_DGRAM, protocol = IPPROTO_UDP)
socket.bindAddr(port = Port 9999)
while running:
let msg = waitfor socket.recvFrom(withSize)
if msg.data.strip.toLowerAscii == "quit":
running = false
echo "message data: ", msg.data
echo "from addr: ", msg.addres
echo "with port: ", msg.port.int
Run