B4J Question Websocket server and multiple connections

marcick

Well-Known Member
Licensed User
Longtime User
I'm playing with WebSocket to estabilish a connection between the server and a B4A/B4I application.
I have read that is possible to manage multiple connections, but It's not clear to me how to implement it.

Supposing to estabilish 100 connections between the server and clients1 to clients100.
Now I want the server to send a message to client5.
How can the server know who is the client5 and how the send message only to him ?
 

OliverA

Expert
Licensed User
Longtime User
I have read that is possible to manage multiple connections, but It's not clear to me how to implement it
It's pretty much done for you. That (stateful connection, with caveat) differentiates WebSockets from plain HTTP (stateless connection). It can occur though that a WebSocket gets disconnected (this is the caveat) and you need to deal with reconnecting. As usual, @Erel has an example on how to deal with this situation (https://www.b4x.com/android/forum/threads/server-automatic-reconnecting-websocket.62054/). For a multiple client example that also shows how you can communicate with all the clients from the server, look at the Chat example found here (https://www.b4x.com/android/forum/threads/webapp-web-apps-overview.39811/#content). A custom push framework example can be found here (https://www.b4x.com/android/forum/threads/custom-websocket-based-push-framework.40272/#content). For more WebSocket oriented information as it relates to B4X, just use the search function in this forum.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I saw those threads and was a bit confused what to follow, now I understand I have to study all of them.
Thanks
 
Upvote 0

alvinmb

Member
Licensed User
Longtime User
The server broadcasts its address on the network. Clients listen to the broadcast address. Once the client knows the server address, the client can send its IP to the server. The server stores the client address and can then direct messages back to individual clients.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User

Thank you. I still have to study all that stuff above. Hope next week.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…