B4J Question Sending a clients List from AsyncStreamText

Addo

Well-Known Member
Licensed User
i am trying to send the connected client list in the server using map and json as following


B4X:
Public Sub SendClientList(Meclient As TcClient)
If clients.Size > 0 Then
  
Dim muser As Map
Dim jsgen As JSONGenerator
  
muser.Initialize

For i =  clients.Size -1 To 0 Step -1
  
Dim aClient As TcClient


aClient = clients.Get(i)

If (aClient.iamconnected = 1) Then

muser.Put("cname", aClient.username)
muser.Put("cEmail", aClient.Email)

End If

Next

jsgen.Initialize(muser)

Dim clientsListstring As String

clientsListstring = jsgen.ToString

Meclient.SendData(clientsListstring)         
          
End If
  

End Sub

i excpected to have a lines of record as example

{"cname":"user1","cEmail":"user1email"}
{"cname":"user2","cEmail":"user2email"}
{"cname":"user3","cEmail":"user3email"}
{"cname":"user4","cEmail":"user4email"}


etc....


its sends only one record even if there 1000 clients connected what i am doing wrong ?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
create a list first,
move the dim muser into the loop
add the muser in the loop to the list.
 
Upvote 0
Top