Astreams error

Rusty

Well-Known Member
Licensed User
Longtime User
I am running a TCPService that when it starts connects to a server (PC).
After handshakes and buffersizes are negotiated (several volleys of successful communication), it gets an Astreams error and I lose my connection.
I've viewed the unfiltered logs, but don't understand what I am seeing.
What seems to be occuring, if this is discernable from the below log?
B4X:
Removed alarm Alarm{417126d8 type 0 myapp.b4a.testapp} type:RTC_WAKEUP
Added alarm Alarm{418e75c0 type 0 myapp.b4a.testapp} type:RTC_WAKEUP when: At 2/14/13 8:28 AM
java.net.SocketException: shutdown failed: EBADF (Bad file number)
    at java.net.PlainSocketImpl.shutdownInput(PlainSocketImpl.java:368)
    at java.net.Socket.shutdownInput(Socket.java:609)
    at anywheresoftware.b4a.objects.SocketWrapper.Close(SocketWrapper.java:155)
    at myapp.b4a.testapp.tcpservice._astreams_terminated(tcpservice.java:421)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
    at anywheresoftware.b4a.BA$3.run(BA.java:303)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
Removed alarm Alarm{418e75c0 type 0 myapp.b4a.testapp} type:RTC_WAKEUP
Added alarm Alarm{418937e8 type 0 myapp.b4a.testapp} type:RTC_WAKEUP when: At 2/14/13 8:28 AM
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: shutdown failed: EBADF (Bad file number)
    at libcore.io.Posix.shutdown(Native Method)
    at libcore.io.ForwardingOs.shutdown(ForwardingOs.java:116)
    at java.net.PlainSocketImpl.shutdownInput(PlainSocketImpl.java:366)
    ... 16 more
  Astreams terminated (Exception) Not initialized
Removed alarm Alarm{418937e8 type 0 myapp.b4a.testapp} type:RTC_WAKEUP
Added alarm Alarm{4183f720 type 0 myapp.b4a.testapp} type:RTC_WAKEUP when: At 2/14/13 8:28 AM
battery level:100 plugged:1
Triggered Alarm 4139e860 RTC_WAKEUP IntentSender{415f6f78: PendingIntentRecord{41399a80 com.android.vending startService}}

Thanks
 

Rusty

Well-Known Member
Licensed User
Longtime User
Here are both Astreams_Error and Astreams_Terminated:
B4X:
Sub Astreams_Error
    WeAreConnected = False
   
    If Socket1.IsInitialized Then 
        Socket1.close
    End If
    If Astreams.IsInitialized Then
        Astreams.close
    End If
Fn.logit("Astreams error " & LastException)
    RescheduleService(3000)    'retry in 3 seconds
    If XferFile.Sending OR XferFile.Receiving Then
        XferFile.Initialize                            'reset all transfer flags/filenames        
        CallSub(Main,"MRNDownloadFail")
    End If
End Sub
    
Sub Astreams_Terminated
    WeAreConnected = False
   
    WaitingOnSocket = 0
    IncomingMsgLength = 0 
    IncomingBufferChannel = 0
    IncomingBufferPointer = 0
    If Socket1.Connected Then
        Socket1.close
    End If
    If Astreams.IsInitialized Then
        Astreams.Close
    End If
    XferFile.Receiving = False
    XferFile.Sending = False
    
    ResetIncoming
Fn.logit("  Astreams terminated " & LastException )
    RescheduleService(3000)    'retry in 3 seconds
End Sub
Thanks Erel
 
Upvote 0

mr23

Active Member
Licensed User
Longtime User
Erel, Regarding (1.) in your above post...

B4a-Bridge does a stream close in Update Status, called from _Terminated.

B4X:
Sub Streams_Terminated
    If Sender <> Streams Then Return
    UpdateStatus(False, True)

Sub UpdateStatus (Connected As Boolean, AllowFurtherConnections As Boolean)
    ConnectedStatus = Connected
    If Connected Then
    Else
        If Streams.IsInitialized Then Streams.Close
 
Upvote 0
Top