Hello All,
I'm new to nim and I'm having some trouble figuring out what I'm doing wrong in this code. I'm getting an error that the sendTo, createThread, and joinThread procs are not defined. The "Thread" type is also undefined. Any help would be much appreciated.
Nim Compiler Version 0.19.9 [Linux: amd64]
import net
proc udp_server() {.thread.} =
var server = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
server.bindAddr Port(3000)
echo "server bound to port 3000"
while true:
var
data = ""
address = ""
length = 64
port: Port
discard server.recvFrom(data, length, address, port)
echo address, " send ", data, " by ", $port
discard server.sendTo(address, port, "server echo back " & data)
if data == "exit":
break
proc udp_client(data: string) =
var socket = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
for count in 1 ..< 5:
discard socket.sendTo("localhost", Port(3000), data)
var
data = ""
address = ""
senderport: Port
length = 64
discard socket.recvFrom(data, length, address, senderport)
echo data
discard socket.sendTo("localhost", Port(3000), "exit")
var thread: Thread[void]
createThread[void](thread, udp_server, nil)
udp_client("test")
joinThread(thread)
Thanks
Hi,
Thanks. That cleaned up the thread proc errors, but I'm still getting the following.
udp_test.nim(17, 26) Error: expression 'sendTo(server, address, port, "server echo back " & data)' has no type (or is ambiguous)
According to the docs, the code seems to be correct. I'm not sure what the issue is.
Thanks