Android Question Send hex bytes to TCP

Sergey_e

Member
Hi everyone!
I'm new to B4A. Programming in VB.net
I want to make a project for a mobile phone to send and receive data over TCP.
I used an example of TestSockets. But my controller (USR K7) does not accept the data I send to HEX.
For example, in vb.net I have a data packet: FF A1 C3 01 10 FD. But in this example, the same packet is not formed. I ask you to help me find a mistake.
 

Attachments

  • TestSockets.zip
    458.6 KB · Views: 112

Erel

B4X founder
Staff member
Licensed User
Longtime User
Start with this example: [B4X] [B4XPages] Network + AsyncStreams + B4XSerializator
Never implement communication code in activities. Switch to B4XPages.

You are sending the hex as string.
Send the bytes directly:
B4X:
Dim buffer() As Byte = Array As Byte(0xFF,0xA1,0xC3,0x01,0x10,0xFD)
AStream.Write(buffer)

You are using AsyncStreams in prefix mode. This will only work if the client also implements this protocol.
 
Upvote 0

Sergey_e

Member
Thank you! It works!
There's another question. How do I substitute data from a text field.
Dim buffer() As Byte = Array As Byte(txt_out.Text)
It doesn't work like that
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
And how to get an answer from the device?
See the example Erel linked.
Incoming data are inside the newdata event
B4X:
Sub AStream_NewData (Buffer() As Byte)
End Sub

For any new Question you should create a new thread.
 
Upvote 0
Top