Android Question Array of bytes from an input stream

FreeWolF

Active Member
Licensed User
Longtime User
Hello, how can I put in an array an input stream from an asyncstream?

This is the code:

B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Server As ServerSocket 
Dim Socket1 As Socket
Dim AStreams As AsyncStreams

End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Private Button1 As Button
Private Button2 As Button
Private EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:

Activity.LoadLayout("Main2")

If FirstTime Then
Server.Initialize(5555, "Server")
Server.Listen 
End If 

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub Button2_Click

End Sub

Sub Button1_Click

Socket1.Initialize("Socket1")
Socket1.Connect("192.168.1.2", 5555, 5000)



End Sub

Sub Socket1_Connected(Connected As Boolean)As Boolean

If Connected = True Then
ToastMessageShow("Connected",True)
Else
ToastMessageShow("Error",True) 
End If

End Sub


Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)

AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams")

If Successful Then
Socket1 = NewSocket

AStreams.write(Array As Byte(0x16,  0x08,  0x00,  0x00,  0x00,  0x00, 0xE3, 0x2C))
ToastMessageShow("Connesso-OK",True)
End If 


Server.Listen

End Sub

Sub AStreams_NewData (Buffer() As Byte)

Dim a As Byte
a = AStreams.StreamReceived

EditText1.Text = a


End Sub

When I start the application, the app send the array of bytes to the board, and the board have to "reply" with the same string. But in the edittext, I visualize only a "0". I think is the first character of an array of bytes, in fact the board have to reply to me THE SAME ARRAY I had sent (0x16, 0x08, 0x00, 0x00, 0x00, 0x00, 0xE3, 0x2C).

What I have to add or modify in my code?
 
Last edited:

FreeWolF

Active Member
Licensed User
Longtime User
Thanks for The reply Erel! I Don't need to reply with The same data, is The board that have To reply To me The same string I had sent To. I need To Read The board reply And put It in a edittext
 
Last edited:
Upvote 0

3394509365

Active Member
Licensed User
Longtime User
I have a similar problem, this is my array
B4X:
ButtonSendMessage.Tag As Byte = Array (0x0B, canb, 0x00, VAL2, 0x0B, canb, VAL3, Value4, 0x0C, DELETE, Val5, 0x00)
'

I wish, however, that the VAL2 VAL3 Value4 and VAL5 are editext.text from the tablet

But I can not find a way to make it work
 
Upvote 0

3394509365

Active Member
Licensed User
Longtime User
i have a similar problem, this is my array
B4X:
ButtonSendMessage.Tag As Byte = Array (0x0B, canb, 0x00, VAL2, 0x0B, canb, VAL3, VAL4, 0x0C, CanC, Val5, 0x00)
'

I wish, however, that the VAL2 VAL3 VAL4 and VAL5 are editext.text from the tablet

But I can not find a way to make it work
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you have made sure that the values returned from the edittexts are integers in the correct range, you can just insert them in to the array. Or better, assign then the the variables first
B4X:
Dim VAL2 AS int = EditText1.Text
Dim VAL4 AS int = EditText2.Text
Dim VAL5 AS int = EditText3.Text

ButtonSendMessage.Tag As Byte = Array (0x0B, canb, 0x00, VAL2, 0x0B, canb, VAL3, VAL4, 0x0C, CanC, Val5, 0x00)

As I wrote in my post on the other thread, VAL3 Must always be 0x20
 
Upvote 0
Top