Android Question Socket stream receive always stop about 5 minutes later

chhtest

Member
Licensed User
Longtime User
Hi,
I use Socket object from Network v1.25 library.

try1:
use do while-loop and inputstream BytesAvailable and ReadBytes method.

try2:
use AsyncStreams object from RandomAccessFile v2.00 library
and _NewData event receive inputstream

try1 and try2 test about 5 minutes late, it stop running, not any error, crash, APP still running, but not stream data response.
always about 5 minute later, it amazing! but before 5 minutes is ok , inputstream receive is fine.
why?

sorry for my poor english.

Frederick.
 
Last edited:

hogiebaer

Active Member
Licensed User
Longtime User
you are from germany ?

the use of async is the better way, but you have also use the events
_AStreams_Error (to determine if the stream is corrupted or the socket connection is broken)
_AStreams_Terminated
 
Upvote 0

chhtest

Member
Licensed User
Longtime User
You should use AsyncStreams and handle the Error and Terminate events to see what happened.
Hi, Erel:
About 5 minutes later, always.

test:
ASUS ZenPhone
ASUS Nexus7 2013
Samsung Galaxy S4

thanks.
Frederick



B4X:
Sub Process_Globals
    Dim Const ZbWsnWifiApAddr As String = "10.10.100.254"
    Dim Const ZbWsnWifiApPort As String = "8899"
    Dim Const ZbWsnWifiApTimeout As Int = 5000 'ms
    Dim IsKeepAliveSet As Boolean = False
    Dim pws As PhoneWakeState
    Dim SocketAsyncStreams As AsyncStreams
    Dim WsnSocket As Socket 
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Activity.LoadLayout("Layout1")
    If IsKeepAliveSet = False Then
        pws.KeepAlive(True)
        IsKeepAliveSet = True
    End If
    WsnSocket.Initialize("WsnSocket")
    WsnSocket.Connect(ZbWsnWifiApAddr, ZbWsnWifiApPort, ZbWsnWifiApTimeout)
End Sub

Sub Activity_Resume
    Log("Activity_Resume()")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Log("Activity_Pause()")
    If UserClosed Then
        pws.ReleaseKeepAlive
    End If
    WsnSocket.Close 
End Sub

'=============================================
' wsn socket
'=============================================
Sub WsnSocket_Connected(Successful As Boolean)
 
    If Successful = False Then
        Log("not connected")     
    Else
        Log("connected ok")     
        SocketAsyncStreams.Initialize(WsnSocket.InputStream, WsnSocket.OutputStream, "SocketAsyncStreams")
    End If
End Sub
Sub SocketAsyncStreams_NewData(Buffer() As Byte)
    Dim i As Int
    i = Buffer.Length
    Log("Stream Len:" & i)

End Sub

Sub SocketAsyncStreams_Error
    Log("SocketAsyncStreams_Error")
End Sub

Sub SocketAsyncStreams_Terminated
    Log("SocketAsyncStreams_Terminated")
End Sub
 

Attachments

  • terminated.png
    terminated.png
    38.2 KB · Views: 141
Last edited:
Upvote 0

chhtest

Member
Licensed User
Longtime User
you are from germany ?

the use of async is the better way, but you have also use the events
_AStreams_Error (to determine if the stream is corrupted or the socket connection is broken)
_AStreams_Terminated

Hi,hogiebaer:
I'm not from germany.
_AStreams_Terminated event is to ececute , not error.

Frederick.
 
Upvote 0
Top