B4J Question UDPSocket how does it work?

ilan

Expert
Licensed User
Longtime User
hi

i would like to understand how the UDPSocket library works. if i have a server that opens a connection and listen to a port like 5000 now i want a client to send a Packet to the server or send a Packet to another client through the server how is that possible?

is there a simple example available?

thank you 🙏
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is no server and client. There are only clients. You use UDPSocket to listen to incoming messages and send UDPPackets to other "clients".

You can also send a packet to multiple "servers" by sending it to the broadcast address. This is demonstrated in this old example: https://www.b4x.com/android/forum/threads/mqtt-chat-with-auto-discovery.75713/#content
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
There is no server and client. There are only clients. You use UDPSocket to listen to incoming messages and send UDPPackets to other "clients".

You can also send a packet to multiple "servers" by sending it to the broadcast address. This is demonstrated in this old example: https://www.b4x.com/android/forum/threads/mqtt-chat-with-auto-discovery.75713/#content

thank you erel i managed to create a simple b4a and b4j app and send packets between them.
i have read that UDP is much faster than TCP because TCP expects a response, not like a UDP connection.

so i see a very big potential for a multiplayer game framework using UDP. the idea is to send stats from a b4x app to another b4x app and like this update the game stats on both apps. in games where the game stats update every few milliseconds, it is less important to know the last sent stat because it is no more relevant so if the packet did not arrive the game can keep going on and for that is UDP a better choice and if i need to verify that the packet arrived on the other side i could use a TCP request. (i guess) 😁

big topic!
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Upvote 0

ilan

Expert
Licensed User
Longtime User


Enjoy...

very nice Peter!
i am working on a more complex game. as soon as i will have a working alpha version i will create a thread about it in the game section.
i think that this topic is not talked about enough in this forum i hope to change it :)
 
Upvote 0
Top