B4J Question AsyncStreamText Send data as Queue

Addo

Well-Known Member
Licensed User
Longtime User
i am trying to handle a huge requests within the server by sending data From each Client Class as a Queue

in the Client Class i have setup a Timer

B4X:
Dim SendTimerQueue As Timer
Dim ClientCMdList As List
Dim SendingQueue As Boolean

and each Time the Timer Fired it should handle the list of commands to be sent as Following


B4X:
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(socket As Socket, Serv As Tcserver)
ClientCMdList.Initialize
SendTimerQueue.Initialize("SendTimerQueue", 1000)
Aserver = Serv
astream.Initialize(Me, "AStream", socket.InputStream, socket.OutputStream)   
End Sub


Sub SendTimerQueue_tick
    
If ClientCMdList.IsInitialized Then
    
If ClientCMdList.Size > 0 Then
    
If SendingQueue = True Then
Return
End If

SendingQueue = True


For i =  ClientCMdList.Size -1 To 0 Step -1

Dim Cmdstr As String

Cmdstr = ClientCMdList.Get(i)

astream.Write(Cmdstr)

ClientCMdList.RemoveAt(i)
    
Next



SendingQueue = False



End If

    
End If
    
End Sub


But The astream.Write(Cmdstr) doesn't send data in loop i should call sleep() in the loop in order to make it send properly

B4X:
For i =  ClientCMdList.Size -1 To 0 Step -1



Dim Cmdstr As String



Cmdstr = ClientCMdList.Get(i)



astream.Write(Cmdstr)

ClientCMdList.RemoveAt(i)

sleep(50)

Next


any idea why i cannot send in loop without calling sleep() ?

is there any proper way to handle this better ?


any idea why ?
 

Addo

Well-Known Member
Licensed User
Longtime User
You are really wasting your time. Building a server with sockets is of course possible but is not so simple.
You should instead use MQTT or jServer to build the server.
The thing is i am creating this socket server to be connected to other socket client that i have made with other language.
Thats why i needed to build a socket server.

I am aware about jserver but at the moment i need to built a socket server
 
Upvote 0
Top