I am trying to get the basics down of using B4XSerializator to communicate with a VB.NET server.
I get a "Header Checksum Illegal" in the VB code after ConvertBytesToObject on ReadObject at Dim t As Byte = br.ReadByte(). Code attached is my attempt to convert Erel's C# code to VB.
After researching the error I inspected the bytes received on the server. In a previous post, one of the Erels stated that the byte stream should start with 0x78, 0x9C.
Mine does not. The first six bytes are 0x50,0x00,0x00,0x00,0x78,0xEF.
Any idea what I am doing wrong?
Marc
B4A Code:
VB.NET Code:
I get a "Header Checksum Illegal" in the VB code after ConvertBytesToObject on ReadObject at Dim t As Byte = br.ReadByte(). Code attached is my attempt to convert Erel's C# code to VB.
After researching the error I inspected the bytes received on the server. In a previous post, one of the Erels stated that the byte stream should start with 0x78, 0x9C.
Mine does not. The first six bytes are 0x50,0x00,0x00,0x00,0x78,0xEF.
Any idea what I am doing wrong?
Marc
B4A Code:
B4X:
Sub Process_Globals
Private ser As B4XSerializator
Type MyMessage (sndData As String)
End Sub
Sub WriteTestData
Dim mm As MyMessage
mm.Initialize
mm.sndData = "Hello!"
Log("Sending mm")
CallSub2(Starter, "SendData", ser.ConvertObjectToBytes(mm))
End Sub
B4X:
Protected Sub ClientSession()
Dim myCompleteMessage As StringBuilder = New StringBuilder()
Debug.Print("ClientSession = " & clientSocket.Connected)
If clientSocket.Connected = False Then
Debug.Print("Client Not Connected")
Return
End If
While (True)
If clientSocket.Connected = False Then
Debug.Print("Disconnect")
Exit While
End If
Try
Dim networkStream As NetworkStream = clientSocket.GetStream()
Debug.Print("canRead = " & networkStream.CanRead)
If networkStream.CanRead Then
Dim myReadBuffer(1024) As Byte
Dim numberOfBytesRead As Integer = 0
Debug.Print("DataAvailable = " & networkStream.DataAvailable)
' Incoming message may be larger than the buffer size.
Do
numberOfBytesRead = networkStream.Read(myReadBuffer, 0, myReadBuffer.Length)
myCompleteMessage.AppendFormat("{0}", Encoding.UTF8.GetString(myReadBuffer, 0, numberOfBytesRead))
Loop While networkStream.DataAvailable
Debug.Print("Received Bytes = " & myCompleteMessage.Length)
' Print out the received message to the console.
Debug.Print("You received the following message : " + myCompleteMessage.ToString())
End If
Catch ex As Exception
Debug.Print(ex.ToString)
End Try
If myCompleteMessage.Length > 0 Then
Debug.Print(vbCrLf & "DESERIALIZE")
Dim ByteArray As Byte() = System.Text.Encoding.UTF8.GetBytes(myCompleteMessage.ToString())
Dim B4Xs As New B4X.B4XSerial
Debug.Print(myCompleteMessage.ToString)
MsgRecord = B4Xs.ConvertBytesToObject(ByteArray)
End If
End While
End Sub