Android Question AsyncStream & return (response)

luke2012

Well-Known Member
Licensed User
Longtime User
Hi all,
I'm using:

B4X:
AStreams.Write(aPrintBuffer.GetBytes("ISO88591"))

To write some data to a target device (in case a printer).
Ho to be sure that the target device has got the data that I sent and processed it successfully ?

Thanks in advance for your reply.
 

luke2012

Well-Known Member
Licensed User
Longtime User
If AsyncStreams_Error and terminated events were not raised then the data was supposedly sent successfully.

How is the printer connected to the Android device? Bluetooth?
If it is Bluetooth or TCP (Socket) then you can assume that the data arrived successfully.

First of all... thanks for your reply Erel.
The printer is connected via Socket connection.

So I have to handle also AsyncStreams_Error and terminated events not only the socket errors. If I understood correctly?
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
That's true.

I did a test. This is the code:

B4X:
Sub AStreams_Error
      Log ("AStream error..." & LastException.Message)
End Sub

Sub AStreams_Terminated

      Log ("AStreams Terminated..." & LastException.Message)

End Sub

I see that the AStreams_Error is raised when a .Connect() fails.
I don't understand when AStreams_Terminated is raised ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
AStreams_Error cannot be raised when you call connect as AStreams is only initialized after the connection has been established.

Generally speaking you should treat the Error and Terminated events in the same way. You can call AStreams_Terminated from AStreams_Error.
If the other side gracefully closed the connection then the Terminated event will be raised.
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
AStreams_Error cannot be raised when you call connect as AStreams is only initialized after the connection has been established.

Generally speaking you should treat the Error and Terminated events in the same way. You can call AStreams_Terminated from AStreams_Error.
If the other side gracefully closed the connection then the Terminated event will be raised.

No error was raised if the target connected device (ex. printer) is offline / powered off?
 
Upvote 0
Top