B4J Question Websocket & custom types

LucaMs

Expert
Licensed User
Longtime User
How to send/receive custom types?

Certainly there is a better method... also because... this does not work :D

I'm trying:
B4X:
' SERVER - WEBSOCKET CLASS
Sub Class_Globals
    Type tProva(ID As Int, Name As String)
    Private mB4XSerializator As B4XSerializator
    Private mStringUtils As StringUtils
'...


Private Sub Test
   Dim Prova As tProva
   Prova.Initialize
   Prova.ID = 123
   Prova.Name = "Me stesso"
 
   Dim Data() As Byte = mB4XSerializator.ConvertObjectToBytes(Prova)
   Dim Base64 As String = mStringUtils.EncodeBase64(Data)

   Dim lstData As List
   lstData.Initialize
   lstData.Add(Base64)
 
   ws.RunFunction("TestRoutine", lstData)
   ws.Flush
End Sub



B4X:
' CLIENT
' [mStringUtils, mB4XSerializator and tProva are declared, of course]

' Called by Private Sub ws_TextMessage(msg As String)
Public Sub TestRoutine(Params As List)
   Dim Base64 As String = Params.Get(0)
   Dim Data() As Byte = mStringUtils.DecodeBase64(Base64)
   Dim Prova As tProva
   Prova = mB4XSerializator.ConvertBytesToObject(Data)
   LogColor("Ricevuti: " & Prova.ID & TAB & Prova.Name, Colors.Blue)


Error occurred on line: 181 (srvComm)
java.lang.RuntimeException: java.lang.ClassNotFoundException: .......$_tprova
 
Last edited:

OliverA

Expert
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Here's the code. Please note they are just quick adaptations of what you posted/was already posted on these forums (no original code). The B4J app is just a shell to log the result of the transfer.
Note: Change the IP addresses!
 

Attachments

  • B4A_Client.zip
    8.7 KB · Views: 275
  • B4J_Client.zip
    1.9 KB · Views: 275
  • Server.zip
    1.4 KB · Views: 276
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
In your client app, is the TProva Type declared in the Main module?
I have already deleted all; anyway, probably I declared it in the service I use for "communications" between the websocket handler "class" and the rest of the app (mainly activities).

Also, I don't think it should change something, @Roycefer, thank you.
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top