Android Question Unexpected end of stream on Connection using OkHttpUtils2

Luis Felipe Andrade

Member
Licensed User
Hello I am doing a chat session using Httputils2, when starting the chat user1 writes something and it is inserted into a WEB database, then with a timer every 10 seconds I make a query to the database, If user2 responds the interaction start, I have noticed that during the waiting time it seems that the channel is saturated with the requests showing the following error message: "Error: java.io.IOException: unexpected end of stream on Connection {MyserverName.com:80 , proxy = DIRECT hostAddress = MyServerName.com / MyserverIP: 80 cipherSuite = none protocol = http / 1.1}
The Programs do not crash but the message shows on the UI
I saw some solution requesting reestart the server, but is a WEBservice server
After some time the program recover and works just fine but after time it show the message again
The error Generate when ExecuteRemoteQuery

I will appreciate any help, I've a few months working with B4A, thanks in advance

Here my Code:
B4X:
'the SQL
Sub CargaChat
    Try
        ExecuteRemoteQuery("SELECT * FROM Chat where IdPropiedad= '" & Main.pidlocal  & "' AND IdChat='" & pidchat & "' AND RecibidoLocal='0' and ProveedorNumero='" & pprovid & "' ORDER BY ID", CARGA_CHATS)
        Catch
        Log(LastException.Message)
    End Try
End Sub

Sub ExecuteRemoteQuery(query As String, JobName As String)
    Try
        Dim job As HttpJob
        job.Initialize(JobName, Me)
        job.PostString("http://MyServerName.com/MyPhpfilename.php", query)
    Catch
        ToastMessageShow (LastException.Message,True)
    End Try
End Sub

Sub JobDone(Job As HttpJob)
    If Job.Success Then
        Dim res, c1,c2,c3,c4, cns, cc, ctc,c As String
        Dim rr As Int
        res = Job.GetString
        Dim parser As JSONParser
        parser.Initialize(res)
        Select Job.JobName
            Case CARGA_CHATS
                Dim l As List
                l = parser.NextArray
                Try
                    If l.Size = 0 Then
                    Else
                        pchatupdate=""
                        lista4. Initialize
                        For i = 0 To l.Size - 1
                            Dim m As Map
                            m = l.Get(i)
                            mapa4.Initialize
                            mapa4.Put ("Id",m.Get("Id"))
                            mapa4.Put ("Ml",m.Get("MensajeLocal"))
                            mapa4.Put ("Me",m.Get("MensajeExterno"))
                            mapa4.Put("Ca",m.Get("Cantidad"))
                            mapa4.Put("De",m.Get("Descripcion"))
                            mapa4.Put("Pr",m.Get("Proveedor"))
                            lista4.Add(mapa4)
                        Next
                        'Panel3.Visible=True
                        Dim xui As XUI
                        Dim ri As RoundImage
                        For ee=0 To lista4.Size-1
                            Dim xui As XUI
                            Dim p As B4XView = xui.CreatePanel("")
                            Dim val As Double
                            Dim bansihay As Int
                            p.SetLayoutAnimated(100,0,0,100%x,20dip)
                            p.LoadLayout ("ordchat")
                            mapa4=lista4.Get(ee)
                            If mapa4.Get("Ml")<>"" Then
                                orderLabel1.Text = orderLabel1.Text & mapa4.Get("Ml")
                                orderLabel1.Color= Colors.ARGB(255,59,65,152)
                                bansihay=1
                            End If
                            If mapa4.Get("Me")<>"" Then
                                orderLabel1.Text = orderLabel1.Text & mapa4.Get("Me")
                                orderLabel1.Color= Colors.ARGB(255,77,144,179)
                                bansihay=1
                            End If
                            If mapa4.Get("Ca")<>"" Then
                                Label60.Text=NumberFormat2(mapa4.Get("Ca"),0,2,2,False)
                                label56.Visible=True
                                Label61.Visible=True
                                Label60.Visible=True
                                Label60.Text=NumberFormat2(mapa4.Get("Ca"),0,2,2,False)
                                If Main.pidioma="1" Then Label61.Text="Confirmar"
                                If Main.pidioma="2" Then Label61.Text ="Confirm"
                                'orderLabel1.Text = orderLabel1.Text & mapa4.Get("Me")
                                orderLabel1.Color= Colors.ARGB(255,77,144,179)
                                bansihay=1
                            End If
                          
                            If mapa4.Get("De")<>"" Then
                            pdescrip=mapa4.Get("De")
                              
                            End If
                          
                            orderLabel1.Text= "   " & orderLabel1.Text  & "   " & prhora & ":" & prminutos
                            Log (Len(orderLabel1.Text))
                            If Len(orderLabel1.Text)<73 Then p.SetLayoutAnimated(100,0 ,0,100%x,20dip)
                            If Len(orderLabel1.Text)>=73 Then p.SetLayoutAnimated(100,0,0,100%x, 38dip)
                            If Len(orderLabel1.Text)>=146 Then p.SetLayoutAnimated(100,0,0,100%x,56dip)
                            If Len(orderLabel1.Text)>=219 Then p.SetLayoutAnimated(100,0,0,100%x,72dip)
                            If Len(orderLabel1.Text)>=292 Then p.SetLayoutAnimated(100,0,0,100%x,90dip)
                            If Len(orderLabel1.Text)>=365 Then p.SetLayoutAnimated(100,0,0,100%x,110dip)
                            If Len(orderLabel1.Text)>=438 Then p.SetLayoutAnimated(100,0,0,100%x,125dip)
                            If Len(orderLabel1.Text)>=511 Then p.SetLayoutAnimated(100,0,0,100%x,146dip)
                                orderLabel1.Height=-2
                            If bansihay=1 Then
                                clv3.Refresh
                                 clv3.add(p,orderLabel1.Text)
                                If Main.pidioma="1" Then label57.Text="Conversaciòn con " & pnombreactual
                                If Main.pidioma="2" Then label57.Text="Chat With " & pnombreactual
                                timer6.Enabled=True         
                            End If
                            bansihay=0
                            pchatupdate=pchatupdate & " OR Id='" & mapa4.Get("Id") & "'"
                Next
                        ExecuteRemoteQuery("UPDATE Chat SET RecibidoLocal='1' where Id='0'" & pchatupdate, INSERTA_ORDEN)
                        Panel3.Enabled= True
                    End If
                    clv3.Refresh
                    Job.Release
                Catch
                    Log ("error 115")
                End Try
                Job.Release
        End Select
    Else
        Log(Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
  
End Sub
 
Last edited:
Top