and i would like in hanlde (for example Conn_1) redirect the resp.OutputStream
to Conn_Ui (and viceversa) i must use resp.SendRedirect?
If it's yes, in what way?
I used resp.SendRedirect("connUi") and after SendObject(map, resp.OutputStream) and raise event in handle of Conn_Ui but not
always and the object received is empty.
Thanks
Example:
<device> to conn1 to connUi to B4jUi and B4j to connUi to conn1 to <device>
Note that resp.SendRedirect will cause url change if you are using a web browser.
It will be more efficient to combine these handlers if possible:
B4X:
srv.AddHandler("/common", "Conn_common", False)
' action in the parameter
/common?action=conn1
/common?action=conn2
/common?action=conn3
/common?action=connUi
' Conn_common
Dim action As String = req.GetParameter("action")
select action
case conn1
...
Information can be shared with session
B4X:
' Conn_1
req.GetSession.SetAttribute("object2share",object2share)
resp.SendRedirect("connUi")
'connUi
dim object2share as Object = req.GetSession.GetAttribute("object2share")
req.GetSession.RemoveAttribute("object2share")
...
Select action
Case conn1
req.GetSession.SetAttribute("object2share",object2share)
resp.SendRedirect("connUi")
Case connUi
dim object2share as Object = req.GetSession.GetAttribute("object2share")
req.GetSession.RemoveAttribute("object2share")
.......
and after creating the various code modules conn1, conn2 .... with their sub Handle, SendObject and ReadObject?
Sub Handle(req As ServletRequest, resp As ServletResponse)
Dim read As Map
read.Initialize
read = ReadObject(req.InputStream)
Dim action As String = req.GetParameter("action")
Select action
Case "conn1"
req.GetSession.SetAttribute("object2share",read)
resp.SendRedirect("connUi")
SendObject(read, resp.OutputStream)
.......
Case "conn2"
Case "conn3"
Case "conn4"
End Select
End Sub
and this in connUi code
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
Dim object2share As Object = req.GetSession.GetAttribute("object2share")
req.GetSession.RemoveAttribute("object2share")
Dim read As Map
read.Initialize
read = ReadObject(req.InputStream)
...........
End Sub
The event in Sub Handle of connUi module it's never raised.
In Conn_common is allright.
Thanks
Excuse billzhan but i have a little confusion.
Ok on how to handle different connections in web server, but how i send the object (map) received in non ui to ui application and viceversa?
Of course not ui and ui are on the same Pc.
it can not be,
the ui application must first receive from the device passing for non ui server and then retransmit the device passing for non ui.
Then i think
device <>http post<>non ui>TcpIp >ui
and non ui<http post<ui
It's right?
trying to make me understand please.....
Device send a object map to non ui server web run on the desktop, in handle non ui connection it read the object map and.......
Now this object must be send to ui application (always on the same desktop) and is this step that confuses me.
How i can activate jobdone in ui application to read a object posted by non ui app?
Excuse me...thanks.
ui app can't handle http request (no http server ), but this should work : ui app ->send http request(every 1 second etc.) -> non-ui app return a map object( map is empty when no information to share) -> ui app jobdone
A simply way is to use shared folders for ui and non-ui app.example:
folder1 : non-ui app write the map object here , ui app check this folder with a timer
folder2 : ui app write map object , non-ui app check this folder with a timer
Checking folders with a timer is an ugly hack and more resource-intensive than it needs to be. Someone wrote the jFileWatcher library precisely for this purpose.
Thanks billzhan and Roycefer, I want to try first con http request
and if it does not work well I try with shared folder and jFileWatcher lib.
A little patience billzhan, you can give me an example of htt request?
Just to be sure, i not expert in http communication.