M micro Well-Known Member Licensed User Longtime User Aug 25, 2015 #1 If I have a server with this connection: Code: Copy srv.AddHandler("/conn1", "Conn_1", False) srv.AddHandler("/conn2", "Conn_2", False) srv.AddHandler("/conn3", "Conn_3", False) srv.AddHandler("/connUi", "Conn_Ui", False) 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> Attachments example.jpg 21.2 KB · Views: 697 Last edited: Aug 25, 2015
If I have a server with this connection: Code: Copy srv.AddHandler("/conn1", "Conn_1", False) srv.AddHandler("/conn2", "Conn_2", False) srv.AddHandler("/conn3", "Conn_3", False) srv.AddHandler("/connUi", "Conn_Ui", False) 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>
B billzhan Active Member Licensed User Longtime User Aug 25, 2015 #2 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: Code: Copy 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 Code: Copy ' Conn_1 req.GetSession.SetAttribute("object2share",object2share) resp.SendRedirect("connUi") 'connUi dim object2share as Object = req.GetSession.GetAttribute("object2share") req.GetSession.RemoveAttribute("object2share") ... Upvote 0
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: Code: Copy 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 Code: Copy ' Conn_1 req.GetSession.SetAttribute("object2share",object2share) resp.SendRedirect("connUi") 'connUi dim object2share as Object = req.GetSession.GetAttribute("object2share") req.GetSession.RemoveAttribute("object2share") ...
M micro Well-Known Member Licensed User Longtime User Aug 25, 2015 #3 billzhan said: It will be more efficient to combine these handlers if possible: Click to expand... Thanks billzhan but I do not understand where to place the various segments of code. I'm not an expert on web server connections. This code is to be entered in the Sub Handle of "Conn_common"? billzhan said: ' Conn_common Dim action As String = req.GetParameter("action") select action case conn1 ... Click to expand... and always in the same Handle.. Code: Copy 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? Best Regards Upvote 0
billzhan said: It will be more efficient to combine these handlers if possible: Click to expand... Thanks billzhan but I do not understand where to place the various segments of code. I'm not an expert on web server connections. This code is to be entered in the Sub Handle of "Conn_common"? billzhan said: ' Conn_common Dim action As String = req.GetParameter("action") select action case conn1 ... Click to expand... and always in the same Handle.. Code: Copy 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? Best Regards
B billzhan Active Member Licensed User Longtime User Aug 26, 2015 #4 micro said: Thanks billzhan but I do not understand where to place the various segments of code. I'm not an expert on web server connections. This code is to be entered in the Sub Handle of "Conn_common"? Click to expand... Yes, in the Sub Handle of "Conn_common". If you can't figure it out , try to share information with session (see previous post) Upvote 0
micro said: Thanks billzhan but I do not understand where to place the various segments of code. I'm not an expert on web server connections. This code is to be entered in the Sub Handle of "Conn_common"? Click to expand... Yes, in the Sub Handle of "Conn_common". If you can't figure it out , try to share information with session (see previous post)
M micro Well-Known Member Licensed User Longtime User Aug 26, 2015 #5 billzhan said: Yes, in the Sub Handle of "Conn_common". If you can't figure it out , try to share information with session (see previous post) Click to expand... Not work This code in Conn_common Code: Copy 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 Code: Copy 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 Upvote 0
billzhan said: Yes, in the Sub Handle of "Conn_common". If you can't figure it out , try to share information with session (see previous post) Click to expand... Not work This code in Conn_common Code: Copy 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 Code: Copy 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
B billzhan Active Member Licensed User Longtime User Aug 27, 2015 #6 see demo attached. Start with the hello world demo will be helpful. https://www.b4x.com/android/forum/threads/server-building-web-servers-with-b4j.37172/ Attachments demo.zip demo.zip 79.7 KB · Views: 579 Upvote 0
see demo attached. Start with the hello world demo will be helpful. https://www.b4x.com/android/forum/threads/server-building-web-servers-with-b4j.37172/
M micro Well-Known Member Licensed User Longtime User Sep 5, 2015 #8 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. Upvote 0
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.
B billzhan Active Member Licensed User Longtime User Sep 5, 2015 #9 If non-ui and ui apps are two seperate jars, ui apps can communicate with non-ui app(server) with http post(s). ui apps -> http post ( b4j map or object ) -> non-ui app(server) -> response to ui apps. see this example : https://www.b4x.com/android/forum/t...olution-device-desktop-and-web-reports.37254/ Upvote 0
If non-ui and ui apps are two seperate jars, ui apps can communicate with non-ui app(server) with http post(s). ui apps -> http post ( b4j map or object ) -> non-ui app(server) -> response to ui apps. see this example : https://www.b4x.com/android/forum/t...olution-device-desktop-and-web-reports.37254/
M micro Well-Known Member Licensed User Longtime User Sep 5, 2015 #10 billzhan said: If non-ui and ui apps are two seperate jars, ui apps can communicate with non-ui app(server) with http post(s). Click to expand... 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? Upvote 0
billzhan said: If non-ui and ui apps are two seperate jars, ui apps can communicate with non-ui app(server) with http post(s). Click to expand... 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?
B billzhan Active Member Licensed User Longtime User Sep 5, 2015 #11 Not sure how you can make it work : non ui>TcpIp >ui Upvote 0
M micro Well-Known Member Licensed User Longtime User Sep 5, 2015 #12 billzhan said: Not sure how you can make it work : non ui>TcpIp >ui Click to expand... 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. Upvote 0
billzhan said: Not sure how you can make it work : non ui>TcpIp >ui Click to expand... 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.
B billzhan Active Member Licensed User Longtime User Sep 6, 2015 #13 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 Upvote 0
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
R Roycefer Well-Known Member Licensed User Longtime User Sep 6, 2015 #14 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. Upvote 0
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.
M micro Well-Known Member Licensed User Longtime User Sep 6, 2015 #15 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. Best regards. Upvote 0
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. Best regards.