I am trying to send an object of a custom defined tuple type over an UDP socket using the sendTo proc from the net module.
I realize that the recipient computer also needs to have this same custom type definition.
The documentation for net says that the data parameter for the lower level version of sendTo must be of type pointer. What's the correct way to get the pointer for my object so that I can send it over the network?
import net
# Define the object type that I want to send over the network
type
MessagePacket = tuple
name: string
age: int
var
mySocket = newSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
reallyWannaSendThis: MessagePacket = ("Joe", 99)
# Attempt to send the object, which won't work this way
mySocket.sendTo("192.168.1.2", Port(9999), ptr reallyWannaSendThis)
I do not have extensive experience with using pointers and my knowledge of C is weak at best. But I do love Nim!
btw.
when you wanna use udp in an async manner, i've written a small library that can do so: