Android Question Websocket library

Philip Prins

Active Member
Licensed User
Longtime User
Hello ,

I use the websocket server to share audio and video to Android and Windows clients.
On Windows (B4J) it works fine but on Android B4A sometimes packets are lost.
Especially on WiFi this happens more often.

Is there another websocket library for B4A or a reason for this?

Regards,
Philip
 

Philip Prins

Active Member
Licensed User
Longtime User
Hello Erel,

It is not in the beginning of the audio but after a number of packets are received.
I keep the device awake so no problems there, it is not all the time that packets are missing.
 
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
B4X:
Sub wsh_RA(Params As List)
    'receive audio from websocket server
 
    
            
            audioStream.StartPlaying
            AppActive = DateTime.Now
            lastServerPong = DateTime.Now
            
            
            Dim RxGSM1() As Byte
            Dim RxM As Map
            Dim RxStR As String
            Dim QL As String
            
            RxM = Params.Get(0)
            RxStR = RxM.Get("A")
            QL = RxM.Get("Q")
            RxName = RxM.Get("N")
            RxGroup = RxM.Get("G")
            
            'Log(RxM)
            If PreviousRxName <>  RxName Then
                ToastMessageShow(RxName&CRLF&RxGroup,False)
                PreviousRxName = RxName
            End If
            
            If Silence = False Then ' if sender is myself don not play audio
            
            
                RxGSM1 = su.DecodeBase64(RxStR)
                    
                
                ''Log("Receiving audio  : "& RxM.Get("X"))
                        
                If QL = "L" Then 'Decode GSM codec
                            
                    'ec")
                            
                            
                    Dim nbytes As Int=RxGSM1.Length
                    Dim bc As ByteConverter
                    Dim ninp As Int
                    Dim ptrx As Int
                    Dim ptrx2 As Int=0
                    ''Log("Got N. Bytes: " & nbytes)
                    Dim lungbuf As Int =nbytes/33*Buffersizeslash2
                    Dim buffbyte(lungbuf) As Byte
                    Dim bufgsm(33) As Byte
                    Dim buffint(160) As Short
                    Try
                        ptrx2=0
                        For ninp =0 To nbytes-1 Step 33
                            bc.ArrayCopy(RxGSM1,ninp,bufgsm,0,33)
                            GSM.decodex(bufgsm,buffint,33)
                            
                            For ptrx = 0 To 158
                              
                                buffbyte(ptrx2+1 ) = Bit.ShiftRight (Bit.And(buffint(ptrx) , 0xFF00), 8)
                                buffbyte(ptrx2) = Bit.And(buffint(ptrx), 0xFF)
                                ptrx2 = ptrx2 + 2
                            Next
                              
                        Next
                        audioStream.write(buffbyte) 'send to play device(speaker or earpiece)
                    Catch
                              
                    End Try
                            
                Else
                    ''Log("PCM codec")
                    audioStream.write(RxGSM1)
'                    If Recording = True Then
'                        output.WriteBytes(RxGSM1, 0, RxGSM1.Length)
'                    End If
                End If
            End If
    
    
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are doing a mistake to use WebSockets for this. Create a regular Socket connection instead. You are adding a lot of overhead.

WebSockets is based on TCP/IP. It will never lose "packets" without breaking the connection. It is possible that you are hitting size limits or sending data faster than it can be received.
 
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
Hello Erel or anyone reading this,

How would you share a upload stream to multiple download streams just like your chat shared example?

Regards,
Philip
 
Upvote 0
Top