Using TIdUDPClient
, my app continuously sends audio data via UDP to another PC running a TIdUDPServer
, which is working well.
Currently, there is no return communication required, but I'm considering a method to ask for a missing packet to be resent. This will be very rare, perhaps once an hour or less.
I'm confused as to what ReceiveTimeout
value to use so that ReceiveBuffer()
will not wait at all if there is nothing in the receive buffer. I've read all the documentation on IdTimeoutDefault
but nowhere does it say what a timeout of -1 actually does. Should I use 0?
Also, currently I'm using SendBuffer()
with an IP and port address every time. Do I need to use Connect()
instead before I can receive data?
When a timeout in Indy is set to IdTimeoutDefault
(-1), it gets treated as IdTimeoutInfinite
(-2). So yes, if you want ReceiveBuffer()
to not wait, use a timeout of 0.
UDP is connection-less, so you do not need to call Connect()
to receive packets. If you omit it, you can receive packets from any peer that sends to your socket's bound IP/Port. Using Connect()
allows you to accept packets only from a specific peer IP/Port, packets received from anywhere else will simply be ignored by the OS.
Connect()
also allows you to set a specific peer IP/Port where subsequent sends will go to, so you don't have to specify the peer on every packet.