Android Question how create websocket server to B4A

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hi all
You can give me the best way to create a websocket in an android app, which acts as a server, to another android application and b4j.

thank in advance
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
yes it is a B4J library. Yes, you can use B4A as a server (see httpserverexample), but I need websockets to keep the connection active and to be able to exchange data between two apps.
Isn´t wecksocket server a b4j library?

As far as i know you can not use Android to be a Websocketserver.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
There is no server side implementation of WebSockets for B4A.

I recommend you to use MQTT instead.


ok. Can I use MQTT to for send image as CCTV camera?
thank you
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What about informing about mqtt and its payload?

I don´t know mqtt much. Don´t know the limit of one message.
But if it is only text then you can create a base64 of an image and send this base64 string.

mqtt expects a bytearray as payload. So it should be possible to send images i guess. I would just use the available methods.
look at the chatexample project.

B4X:
Public Sub SendMessage(Body As String)
    If connected Then
        client.Publish2("all", CreateMessage(Body), 0, False)
    End If
End Sub

Public Sub Disconnect
    BroadcastTimer.Enabled = False
    DiscoveredServer = ""
    CallSub(Main, "UpdateState")
    If connected Then
        client.Publish2("all/disconnect", serializator.ConvertObjectToBytes(Name), 0, False)
        client.Close
    End If
End Sub

Private Sub CreateMessage(Body As String) As Byte()
    Dim m As Message
    m.Initialize
    m.Body = Body
    m.From = Name
    Return serializator.ConvertObjectToBytes(m)
End Sub

As i never used mqtt in production and i just checked one of the available example codes i may be wrong.
But i´m positive that you can create your own Message customType which holds an Image (the bytes, not base64) in one of its properties and use Serializator to convert the customtype into a payload for mqtt. So my answer is YES.
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
i'm trying the symple chat, but have this error:

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