B4J Question [SOLVED] Custom Type over websocket?

techknight

Well-Known Member
Licensed User
Longtime User
Between B4J server and B4A client, I can put a custom Type defined variable inside of a Map to be sent to the B4A App and it works fine as far as I can tell.

But if I try to do the same thing to a B4J websocket client, I get this error:

B4X:
TextMessage Error: (ClassCastException) java.lang.ClassCastException: java.lang.String cannot be cast to md.vscb3000wrestling.main$_scoredata

Here is what I am doing:
B4X:
    Type ScoreData(RedScore As Int, GreenScore As Int, Period As Int, Minutes As Int, Seconds As Int, Milliseconds As Int)
    Public Scores As ScoreData

Scores.Initialize
<code that manipulates info in scores>

Then eventually:
    Dim data As Map
    Dim SendData As List
    SendData.Initialize
    data.Initialize
    data.Put("Scores", ScoreEngine.Scores) 'Insert Score Data to transmit
    SendData.Add(data)
    ws.RunFunction("RefreshDisplayScores", SendData)
    ws.Flush

ScoreData is my customtype. any ideas?
 
Last edited:

techknight

Well-Known Member
Licensed User
Longtime User
Acutally it appears the Try/Catch block inside the WebSocketclient Class is catching the error that my statement is causing. Here:

B4X:
    If Data.ContainsKey("Scores") = True Then
        Scores = Data.Get("Scores")
    End If

Again, Scores is defined as type ScoreData which is my custom type. I can add the custom type into a Map, but when grabbing it back out of the Map is when its causing the problem.

Hmmm....
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Worked precisely the way I needed it to. I didnt realize the TypeDefs were lost over websocket. Whoopsie.

Thanks man.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…