I already have a string variable, which is the ip adress for the packet to be sent, and the event is is raised always in the same instance, but initialize and packet sent in both.
What is so complicated?
The events are raised in the instance where the UDP is initialized.
Create one Class. make it a processglobal public variable.
You then can use the classmethods from any forum using main.youclassvariable.dothis. The events are raised in the class for sure. you can raise an event from the class to the calling form...
It is not complicated, I already tried that and in my case the event was always raised in one instance, not always the correct one.
I use it in nonUI app.
The code I use I quite complicated and I also use it to communicate with the specific device (Broadlink), so it is not possible to test by someone just by posting my code.
That's why I asked for some workings example.
My working solution is to pass the event to the main module and then pass it back to the correct instance identified by the Ip address form the incoming packet.
Just wanted to know if it is a normal behavior or maybe some issue....
Here is the example.
The log output I get is the following:
B4X:
Init d
Auth d
Init d2
Auth d2
Udpsock_PacketArrived instance:192.168.0.20 from host:192.168.0.20
Udpsock_PacketArrived instance:192.168.0.20 from host:192.168.0.21
I would expect the same instance (ip) and from host.
It will be difficult to reproduce without the real devices, but maybe I do something wrong in the code itself.
You will need to give each class instance its own port number. There is no correlation between sending a UDP packet and getting a return answer except for the port number used on the server's sending/receiving side. Looks like whichever class calls the UDPSocket Initialize/Initialize2 method with a given port number will receive the messages sent to/arriving at that port number.
Hi, yes this might be the case.
Thats why in my final solution delegate the events to main module and then pass back to the right instance by checking the list of insances and IP number.
I just wanted to be sure that is the right solution in such a case, where the port numbers are the same in all devices.
Thank you for the clarification of this behaviour.