Byte - UDP

RosarioAR

Member
Licensed User
Longtime User
Hi to all
I have a question in reference to receive a bytes over UDP.
Im testing with an aplication in VB6 for to send the data.

I receive the data in B4A with the next code

B4X:
Sub UDP_PacketArrived (Packet As UDPPacket)

   Dim msg As String
   Dim Buffer1() As Byte

   msg = BytesToString(Packet.data, Packet.Offset, Packet.Length, "UTF8")
   Buffer1=msg.GetBytes("UTF8")

I'm sendig data from VB6 with the next code

B4X:
WinsockTX.SendData (Chr(1) & Chr(2) & Chr(255))

The problem is when i send a char > to 127, in Buffer1 i'm receiving 3 negative values that representing the 128 to 255 values (i'm expecting to receive 1 negative value). This negative values are the same from 128 to 255.

Values from 0 to 127 is OK
Buffer1 = [0=1, 1=2, 2=127]

Values from 128 to 255 Fail
Buffer1 = [0=1, 1=2, 2=-17, 3=-65, 4=-67]

How can i do to receive 1 negative value for next can be transform?

I read several treads respect to that, but im confused with the three negative values..

Thanks
 

Attachments

  • buffer status receiving chars 1 2 127.jpg
    buffer status receiving chars 1 2 127.jpg
    30.2 KB · Views: 170
  • buffer status receiving chars 1 2 255.jpg
    buffer status receiving chars 1 2 255.jpg
    28.8 KB · Views: 164

RosarioAR

Member
Licensed User
Longtime User
Hi Erel.
I'm converting the byte to string using the example in Basic4android - Network

B4X:
Sub UDP_PacketArrived (Packet As UDPPacket)
    Dim msg As String
    msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
    Msgbox("Message received: " & msg, "")
End Sub

Can i get directly the bytes from without convert to string?
I knew that Java use signed bytes, but i expected receive a negative value for then convert this.

Can you advise?
Thanks in advance.
 
Upvote 0
Top