This is an extension to the MQTT chat room example: https://www.b4x.com/android/forum/threads/b4x-mqtt-chat-room.61568/#content
It is a chat room where one of the devices acts as a server and the others as clients.
The difference in this example is that the clients don't need to enter the server ip address.
All devices listen to UDP packets on port 51049.
The server broadcasts its ip address every second. It is done by sending a UDP packet to the broadcast address.
The result is that any device listening on the correct port will receive the message.
The "Connect As Client" button will be enabled when the server ip address is discovered (and the name field is not empty).
Finding the broadcast address:
B4A: https://www.b4x.com/android/forum/threads/75694/#content
B4J / B4i: UDPSocket.GetBroadcastAddress
Note that it can take a few seconds before the broadcast message arrives.
It is a chat room where one of the devices acts as a server and the others as clients.
The difference in this example is that the clients don't need to enter the server ip address.
All devices listen to UDP packets on port 51049.
The server broadcasts its ip address every second. It is done by sending a UDP packet to the broadcast address.
The result is that any device listening on the correct port will receive the message.
The "Connect As Client" button will be enabled when the server ip address is discovered (and the name field is not empty).
Finding the broadcast address:
B4A: https://www.b4x.com/android/forum/threads/75694/#content
B4J / B4i: UDPSocket.GetBroadcastAddress
Note that it can take a few seconds before the broadcast message arrives.
Attachments
Last edited: