B4J Question Socket Closed Error

tufanv

Expert
Licensed User
Longtime User
Hello,

I am running a non ui app on my vps to download a data from remote server and process that data to my database ( the db running on the same server with java app ) via a php file.

First step that downloads data from remote never gives an error , but randomly the second steps gives the following error , there are no patterns , sometimes it gives error 20 out of 25 tries and i cant fix the problem



The error is repating with the following error: I am not familiar much so do you have any idea what may cause it ? The interesting thing is i get this error not while getting the data from remote server but while calling the php file on the same sserver of java app to process to database. I always get basarisiz2 in the logs which is the job fail of calling the local php for the job: datayolla

this is my code:

B4X:
Sub Process_Globals
    Dim timeryenile As Timer
    Dim csu As CallSubUtils
End Sub

Sub AppStart (Args() As String)
    veri_al



    timerayarla
    StartMessageLoop
End Sub
Sub JobDone(Job As HttpJob)



        If Job.JobName="j" Then
            If Job.Success Then
                            'Log(Job.GetString)
                Dim anne As String = Job.GetString
                '    Log(Job.GetSize/1000)
   



       
                Dim yolla As HttpJob
                yolla.Initialize("datayolla", Me)
                yolla.PostString("http:/myserver/foreks.php","action=1&data="&anne)
                yolla.GetRequest.Timeout=2000
           
       
       
   
            Else
                csu.CallSubPlus(Me,veri_al,1000)
                Log("basarisiz1" & DateTime.Date(DateTime.Now))
       
            End If

        End If

        If Job.JobName="datayolla" Then
            If Job.Success Then
                timeryenile.Enabled=True
            Else
                Dim yolla As HttpJob
                yolla.Initialize("datayolla", Me)
                yolla.PostString("http:/myserver/foreks.php","action=1&data="&anne)
                yolla.GetRequest.Timeout=2000
       
                Log("basarisiz2" & Job.ErrorMessage)
                   
                   
            End If
            '            Log(Job.GetString)
   
   
       
        End If
        Job.Release



End Sub
Sub timeryenile_tick
    Try
        Dim gun As Int = DateTime.GetDayOfWeek(DateTime.Now)
   
        If gun=1 Or gun = 7 Then
            timeryenile.Interval=1800000 'her yarim saat
        Else
            timeryenile.Interval=1000
        End If
   
   
   
   
   
        timeryenile.Enabled=False
        veri_al

    Catch
        Log(LastException.Message)
    End Try
End Sub
Sub timerayarla
    timeryenile.Initialize("timeryenile","1000")
    timeryenile.Enabled=False
End Sub
Sub veri_al

    Dim j As HttpJob
    j.Initialize("j", Me)
    j.Download("http://remoteserverishere")
End Sub

B4X:
nohup: ignoring input
java.net.SocketTimeoutException: timeout
    at okio.Okio$4.newTimeoutException(Okio.java:227)
    at okio.AsyncTimeout.exit(AsyncTimeout.java:284)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:240)
    at okio.RealBufferedSource.indexOf(RealBufferedSource.java:325)
    at okio.RealBufferedSource.indexOf(RealBufferedSource.java:314)
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:210)
    at okhttp3.internal.http1.Http1Codec.readResponse(Http1Codec.java:191)
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:132)
    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:54)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179)
    at okhttp3.RealCall.execute(RealCall.java:63)
    at anywheresoftware.b4h.okhttp.OkHttpClientWrapper.executeWithTimeout(OkHttpClientWrapper.java:156)
    at anywheresoftware.b4h.okhttp.OkHttpClientWrapper.access$0(OkHttpClientWrapper.java:153)
    at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$ExecuteHelper.run(OkHttpClientWrapper.java:201)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Socket closed
    at java.net.SocketInputStream.read(SocketInputStream.java:183)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at okio.Okio$2.read(Okio.java:138)
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:236)
 
Last edited:

tufanv

Expert
Licensed User
Longtime User
If you are running the B4J app on your own server which also hosts the database. Why you did not directly write the data to the DB using B4J SQL Object?
I don't know , I will switch to this solution you are right . Why Am I using a php in the middle ? non sense.

So I should follow Erel's post 17 not 18 right ?
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
17 for the DB Connection
18 for the client-connections to your B4J app.
Thanks ! I am waiting for vps provider's changing the apache to nginx. They advised to change and they are changing now , I will wait for that to complete. Thanks for help!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…