'so far, so good: buffer(0) = 250, buffer(1) = 12, buffer(2) = 1, buffer(3) = 32
Sub receive(buffer() As Byte)
'convert four bytes of UTF-8 to Unicode String
'this is where we run off the rails
'250 is never ever ever a valid UTF-8 byte
'but presumably you are expecting it to return a four-character string,
'so let's run with that
Dim s As String
s = BytesToString(buffer, 0, buffer.Length, "UTF8")
'this will get the first character of s - Chr(250)? -
'and put it into a one-character string find32
Dim find32 As String =s.CharAt(0)
'convert that one-character string into a one-byte array data32
'now we have the opposite UTF-8 problem in that U+00FA is > ASCII, and thus will
'not fit into one UTF-8 byte, instead it will become two bytes: 0xC3 0xB8
Dim data32() As Byte
data32=find32.GetBytes("UTF8")
'take the first byte of data32() which is hex: 0xC3, or dec: 195
'and put it into value
Dim value As Byte=0
value=data32(0)
'tbh all bets are off at this point, there are so many possibilities
'of how that invalid UTF-8 got handled
Log("value=" & value)
'I doubt you'll be seeing this log
If value32=32 Then log("Was received 32")
End sub
'also, wondering why first letter of "log" and "sub" not capitalized by the IDE???
'has this code actually been run???