Hello everybody,
I wrote a simple program to update all my IOT device firmware using OTA, when a remote device need an update call me b4j http server that upload a binary stream.
When called from a single device all works good but when multiple devices try to download firmware I get java.lang.IllegalStateException: STREAM.
in main module I declare the server and
in eclservice server handler
the process returnFIRMWARE takes about 10 seconds and when starts several concurrent calls only the first finish the job in the right way all other calls crashes with java.lang.IllegalStateException: STREAM.
What is my mistake ?
I wrote a simple program to update all my IOT device firmware using OTA, when a remote device need an update call me b4j http server that upload a binary stream.
When called from a single device all works good but when multiple devices try to download firmware I get java.lang.IllegalStateException: STREAM.
in main module I declare the server and
main:
Sub Process_Globals
Private srvr As Server
end sub
Sub AppStart (Args() As String)
....
...
srvr.AddHandler("/eclservices/*", "eclservice", False)
....
...
StartMessageLoop
end sub
eclservice:
Sub Class_Globals
Private Request As ServletRequest
Private Response As ServletResponse
Private HRM As HttpResponseMessage
End Sub
Sub Handle (req As ServletRequest, resp As ServletResponse)
Request = req
Response = resp
.......
......
ProcessRequest
end sub
Private Sub ProcessRequest
.....
.....
....
Case "getfirmware"
......
'read from blob field a byte array containing the new firmware
Dim b() As Byte = DB.ReadBlob("my_new_firmware.bin")
utility.ReturnFIRMWARE(b,Response,"my_new_firmware.bin")
....
....
end sub
utility:
Public Sub ReturnFIRMWARE(b() As Byte, resp As ServletResponse,myfileName As String)
Log("[ReturnFIRMWARE]")
resp.ContentType = "application/octet-stream"
resp.SetHeader("Content-Disposition", $"inline;filename=${myfileName}"$ )
resp.SetHeader("Content-Length", $"${b.Length}"$)
resp.OutputStream.WriteBytes(b, 0, b.Length)
Log("[fine][ReturnFIRMWARE]")
End Sub
the process returnFIRMWARE takes about 10 seconds and when starts several concurrent calls only the first finish the job in the right way all other calls crashes with java.lang.IllegalStateException: STREAM.
What is my mistake ?