Hello. This xtra is very useful for my project. But now D11.5 also has ByteArray object. Can you make your asUDP to support ByteArray of D11.5? Thanks.
After I tried it, I found it wouldn't report an error when binding failed. And it can't choose which local address to bind if there is more than one. Hope there will be upgrades soon.
I'm surprised that it does not report an error when binding fails. Normally it does.. At least it reports all the errors reported by the Windows API.
And about local address, you mean that you have multiple network cards and want to select the one to use to bind ? Indeed, for now, I bind to the default address... Will put this on my todo list.
on Mac, I do get an error : "UDP error 'OTBind' ' -3247 The address is in use and is not available for the current function.'"
on Windows, indeed, using an already used port does not return an error (even though it did fail to bind). I'll check if I can do return some error (since Windows API does not). On my todo list.
About listening to a port, yes, this is the way UDP works in general. There is no real notion of 'connection', the basic brick is 'listening' and 'sending'. The basic aspect of UDP is : listening to a port, to which many clients can send. Then if a client wants to receive an answer, it must listen too, to its own port, to which the server will send an answer. This is the basis of the UDP protocol.
If I startListen and then setSendingPort the same port, will there be 2 bindings? There maybe some problems. I have strange situation like this:
Process 1:
startListen(1422)
setSendingPort(1422)
sendBytes to localhost:1423
Process 2:
startListen(1423)
setSendingPort(1423)
sendBytes to localhost:1422
Process 2 can receive data from Process 1, but Process 1 can't receive data from Process 2. The two process are from the same code. I am doing something like STUN to establish P2P connection but get stuck here.
After some experiments I found if I set one port for both sending and receiving, there is 50% chance that it couldn't receive any data. I need to free xtra and recreate it to get another chance. There is no chance before recreating.
If I set different ports, there was no such error.
Can you create one socket for both listening and sending? Or you already do so? I think that can solve the problem.
Yes, this is a problem on Windows, that I've already encountered. When binding the send port and the receive port to the same port, it says that the bind succeeds, but actually no.
The only solution is to test the connection (sending to oneself), and if this fails, close both the sockets and retry.
Sorry about this, but this is a Windows problem as such.