iOS Question Autodiscovery and serialization

nwhitfield

Active Member
Licensed User
Longtime User
In the MQTT auto discovery tutorial, the server broadcasts its IP address using UDP, so clients can find it easily. This is something I'm working with for some of my apps. I've happily got an iOS client discovering an Android server, However, I also have desktop apps, which are built using Xojo.

In the example code, the data to be broadcast is converted to bytes, using the B4X Serializator

B4X:
serializator.ConvertObjectToBytes(server.GetMyWifiIP)

This is fine when working with B4x code, but from the Xojo side, the UDP.Write method simply expects a string, like

B4X:
udp.write(udp.broadcastAddress,"10.0.1.16")

So, I can pass the IP address of the server easily, but when that's received by a B4x app, of course it's not serialized in the same way, and I get an exception using the ConvertBytesToObject

Given that this is only an IP address, is there any good reason I'm not seeing why I shouldn't just use ByteConverter functions to handle this, which would give me compatibility with the Xojo side of my code?

B4X:
Dim ds As String = bc.StringFromBytes(data,"UTF8") ' works with the data sent by Xojo
'Dim ds As String = serializator.ConvertBytesToObject(data) ' chokes on the data sent by Xojo
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Given that this is only an IP address, is there any good reason I'm not seeing why I shouldn't just use ByteConverter functions to handle this, which would give me compatibility with the Xojo side of my code?
No. It is completely fine to use string with ByteConverter or BytesToString method.
 
Upvote 0
Top