B4J Question Micro Webserver with Serversocket

Blueforcer

Well-Known Member
Licensed User
Longtime User
Hey,
im finished jHueBridge wich emulates a Phillips hue bridge so you can control your B4J app with an Amazon Echo for example.
Everything is working using jServer, but to keep it leightwheigt and B4X compatible i want to use Serversocket and Astreams instead.

So i need your help to publish this Lib for everyone.

The first step is, to serve an XML to the Client. This is working (tested by open the url in an browser) but i cannot load this page twice.What i need to do?

B4X:
Sub Process_Globals
    Dim socket As ServerSocket
    Dim astream As AsyncStreams
End Sub

Sub start
    socket.Initialize(80,"socket")
    socket.Listen
    Log("jHueBridge Ready!")
End Sub

Sub Socket_NewConnection (Successful As Boolean, NewSocket As Socket)
    If Successful Then
        astream.Initialize(NewSocket.InputStream,NewSocket.OutputStream,"astreams")
    End If
End Sub

Sub astreams_NewData (Buffer() As Byte)
    Dim s As String = BytesToString(Buffer,0,Buffer.Length,"utf8")
    Log(s)
    Handle(s)
End Sub

Sub Handle(msg As String)
    If msg.Contains("description.xml") Then
        astream.Write(descriptionXML.GetBytes("utf8"))
    End If
end sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top