Android Question How can I use B4XSerializator in VB.NET/C# [Solved]

alimanam3386

Active Member
Licensed User
Longtime User
Hi

I use M2Mqtt client library to connect c# to mosqitto broker in server side . All things is ok I receive simple string data from server in client side ( b4a)

In b4a/b4j we have Type structure like bellow code ( I don't know what is the bellow equals code in C# )

B4X:
Type Message ( id as string , senderid as string , receiverid as string , msg as string )

My question is , how can I get/send this structure in c# side ? I used B4XSerializator but I dont know how can I use it to get/send Type structure like b4a/b4j code in server side ?



any help plz
 
Last edited:

alimanam3386

Active Member
Licensed User
Longtime User

I did see this lib if you look better to my post I said I should use this lib in VB.NET/C# code but the problem is when I define a class in vb.net language I get this error :



qa.jpg
 
Upvote 0

fixit30

Active Member
Licensed User
Longtime User
Sorry, I have not used this before.

You are using it incorrectly, you do not need to create a class, you need to initialise an object of type B4XType.

Something like this:

B4X:
        Dim Dict As New System.Collections.Generic.Dictionary(Of Object, Object)
        Dict.Add("id", "1")
        Dict.Add("senderid", "A")
        Dict.Add("receiverid", "B")
        Dict.Add("msg", txtMessage.Text.Trim)
        Dim B4XMessage As New WpfApplication1.B4XType("Message", Dict)
        client.Publish(txtTopic.Text, b4x.ConvertObjectToBytes(B4XMessage))
 
Upvote 0

alimanam3386

Active Member
Licensed User
Longtime User
Sorry, I have not used this before.

You are using it incorrectly, you do not need to create a class, you need to initialise an object of type B4XType.

Something like this:

B4X:
        Dim Dict As New System.Collections.Generic.Dictionary(Of Object, Object)
        Dict.Add("id", "1")
        Dict.Add("senderid", "A")
        Dict.Add("receiverid", "B")
        Dict.Add("msg", txtMessage.Text.Trim)
        Dim B4XMessage As New WpfApplication1.B4XType("Message", Dict)
        client.Publish(txtTopic.Text, b4x.ConvertObjectToBytes(B4XMessage))

I used your code but I did not receive any message from Client ( vb.net app ) I chenged your code to bellow code and it works :

B4X:
        Dim d As New Dictionary(Of Object, Object)
        d.Add("Id", GetRandom(1, 500))
        d.Add("Msg", txtMessage.Text.Trim)
        d.Add("SenderId", "Windows App")
        d.Add("ReceiverId", "room1")
        client.Publish(txtTopic.Text, b4x.ConvertObjectToBytes(d))
 
Last edited:
Upvote 0
Top