I have created a class that will be used to discover devices on the LAN using UDPSockets. To keep the code somewhat organized. I have this class creating it’s own UDPsockets rather than placing them as controls on a window.
I’m not sure what I am missing but I define:
DiscoverSocket as UDPSocket
In constructor:
DiscoverSocket = new UDPSocket
DiscoverSocket.Port = 4850
Then I’m trying to add a handler for DataAvailable:
However the IDE and compiler complain that there is no DataAvailable member on UDPSocket. But clearly there is from the help and if I stick on on a window.
I also tried subclassing and implementing DataAvailable (which is present when adding an event handler to the subclass). But I still cannot assign the handler.
I have done this successfully for TCPSocket and I’m wondering why it’s failing on UDPSocket. This is xojo 2021 3.1
Well I ended up subclassing UDPSocket for each discovery socket I needed and that seemed to work. In the sub classes I could get to the DataAvailable member.
Hi Andrew. The comma was not the issue. Cut/paste error. The problem still seem to be that trying to directly use a UDPSocket the DataAvailable member is just not there. Not sure why. As I said I got around this by creating my own subclasses and only then did the DataAvailable event handlers become available.
Nope. I have exactly the code you show with the comma in place. … on DiscoverSocket yields NO DataAvailable in the list. Compile error says DiscoverSocket does not contain a member named DataAvailable.
Odd, you won’t see DataAvailable on the autocomplete for DiscoverSocket if that is what you’re referring to? Are you able to replicate that in a simple demo project?
Right mouse click on “UDPSocket” (above code, in the ide) then click New Method → from event → DataAvailable. Now you get a method witth the correct signature and it should work.
The method should have the signature: UDPSocket_DataAvailable(Sender As UDPSocket)
Thanks for the input. I did learn a few things like the right-click which I hadn’t thought of trying.
This was on 2021 R 3.1 on Mac M1Max and yes I did have the comma in place. For whatever reason when typing in the socket and there was no DataAvailable event in the list. So I typed it in. Compiled and got the error. And again, yes I had a comma in place between the event and the address of.
Like I do with most things after doing this for close to 40 years I find another way and the way I found which actually is nicer because I can encapsulate some of the specifics of each discovery socket was to sub class. Once I sub classed DataAvailable could be directly accessed and code put in to deal with the data.
This morning I restarted my Mac. With this M1Max and current OS I haven’t need to restart very often at all. I restarted this morning just because it had been close to 30 days. After restart, in my test program I was going to post here, suddenly DataAvailable is there in the list and it compiles.
No idea, no clue why a restart fixed it. But anyway thanks for all the attention to this thread. I feel that as I undertake this Xojo project I am on that this forum will be a great place to find answers.