Android Question AsyncStreams - Hanging

DeviousD

Member
Licensed User
Longtime User
Hi All,

I used the BT sample project to connect to and have a CHAT session.

I modified to connect to a BT device, that sends me back some information followed by a file.

Using it in non-prefix mode, it reads the information that is text until i get a string that specifies the file size to follow.

Adding the incoming bytes as a string i add them to a string value and after the byte count gets to 22152 byes the app hangs.

Now i did read the fact that i need to put this on a service. So i created a service and placed the AsyncStreams on it with the serial component.

When on the service the APP just closes down and say Bluetooth has stopped working and closes the APP>

So i moved it back to the "chatactivity".

Im not sure how i should be handling this incoming string of text followed by a file apparently a bin file...

Any suggestions?
 

DeviousD

Member
Licensed User
Longtime User
Erel,

I did read thu the documentation and as i'm not controlling the source device i can not use the prefix mode....

What i'm getting from the device is the following, up until the s2031616 which is supposed to be the file size...

i Initialising WiFi
i Searching for SSID
i SSID found: XXX123
i Connecting WiFi
i Connected, waiting for IP address
i IP address assigned: 192.0.0.123
i Opening Socket
i Socket Openend, Requesting File
i Request sent
i Parsing response
s 2031616
[File data - omitted for brevity]
i Download complete


The app hangs as i get about 22152 bytes...

How would i handle a mixture text first which i get and display, and then i get sent as file... suggestions on best handling this....
 
Upvote 0

DeviousD

Member
Licensed User
Longtime User
Maybe some background might help.

Im connecting to a BT device, which in turn connects to a wifi device to pull info from...

So, APP->BT Device ->Wifi device ,

BT device request information from Wifi device, anf then APP gets the feedback from BT device.

Specialized equipment, so i cant connect to the wifi device myself and rely on the BT device to do my initiating processes....
 
Upvote 0

DeviousD

Member
Licensed User
Longtime User
B4X:
Sub fillmydata(mystring As String)

    If myMessageis.Contains("i Parsing reponse") Then
        myFileSize = myMessageis.IndexOf("i Parsing reponse")
    End If
   
    If myMessageis.Contains("i Download Complete") Then
        myFileDone = myMessageis.IndexOf("i Parsing reponse")
    End If


    If (myFileSize >0) Then
        txtLog.Text = "FileSize has been sent.."
        currentFile = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
        ReceivingFile = True
        downloading = True
    End If

    myMessageis = myMessageis & mystring

    txtLog.Text = txtLog.Text & mystring

    txtLog.SelectionStart = txtLog.Text.Length


End Sub


Sub AStream_NewData (Buffer() As Byte)

    fillmydata(BytesToString(Buffer, 0, Buffer.Length, "UTF8"))

    myBytes = myBytes + Buffer.Length

    txtLastReading.Text = myBytes & " Bytes"

    If downloading Then
        ProgressDialogShow("Downloading... "& CRLF &  CRLF & "[ ~ Bytes Recieved ]...".Replace("~", myBytes))
    End If



End Sub


Erel, im not sure how to check when the actual file starts arriving beside possible checking for s_, then switching the data to a new var and streaming it until it ends? how do i then save this stream of data theys stored in currentFile?[/code]
 
Upvote 0

DeviousD

Member
Licensed User
Longtime User
Erel,

Would it be because the UI has to update the txtLog to the frontend all the time forcing a redraw event each time we get some data? As the first few lines of text work quick and are visible within seconds... then after the "file" downloading starts, the activity hangs and evenutally i get a Wait Stop aop error message, the UI does update the bytes on the screen showing, but the app is dead...
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Is txtLog an editTextBox? If so, do you have any code inside thiw editText textChanged sub?
 
Upvote 0

DeviousD

Member
Licensed User
Longtime User
HI

its goes "quiet" after the "i parsing command"....
and then the bytes recieved climbs to 22000 something and the txtLog shows some characters and then nothing. Not sure if the device has run out of memory due to the constant
txtLog.SelectionStart = txtLog.Text.Length

you cant even scroll or even access the txtlog component from the device, its processing and then after 3 minutes if you lucky the keyboard intent popups to match your click of the txtlog component....

rather confused.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…