![]() |
|
Advice about where put a code to websocket - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Atozed Software (https://www.atozed.com/forums/forum-1.html) +--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html) +---- Forum: English (https://www.atozed.com/forums/forum-16.html) +----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html) +----- Thread: Advice about where put a code to websocket (/thread-1126.html) |
Advice about where put a code to websocket - cprmlao@hotmail.com - 07-10-2019 Hi, I have many iw forms, all inherited from a standard iwform(TIWFormStd). I have a MasterTemplate html to all my IWForms. I have my websocket server component in servercontroller module(I don´t know if this is the better place) I need the websocket client available in all forms, because my app has a chat to users. In that MasterTemplate, I have the next script code to connect to websocket server: Code: <script>My problem is that when I open a new iwform, I allways release the old iwform. As the old form is released, the websocket connection in the frontend is destroyed as well and recreated when the new IWForm is active. I´d like to know some suggestions about where I can put the websocket client code to avoid it. Regards, Luiz RE: Advice about where put a code to websocket - Jose Nilton Pace - 07-11-2019 Hi Luiz. What websocket component are you using ?, thank you. RE: Advice about where put a code to websocket - cprmlao@hotmail.com - 07-11-2019 Hi, I am using sgcwebsocket. But I can create a nodejs server using socketio. The server is not a problem. The problem is in the frontend. The js using sgcwebsocket is similar to socketio. When i change the form in front end the webssocket client is closed because the old form is released and recreated with the new form. My app has a chat and i intent to use webssocket or socketio to It. RE: Advice about where put a code to websocket - kudzu - 07-11-2019 You need to store your websocket connection in a global space such as the window object to persist it. RE: Advice about where put a code to websocket - cprmlao@hotmail.com - 07-11-2019 (07-11-2019, 06:15 PM)kudzu Wrote: You need to store your websocket connection in a global space such as the window object to persist it.My forms use MasterTemplate, the js code is into Mastertemplate HTML. Is possível the code survive into window object when I load a new form If the old is released? If yes, could you point me some sample code? I use inherithance in forms. RE: Advice about where put a code to websocket - kudzu - 07-12-2019 My mistake. I'm focused on 17. 17 can persist objects as you wish. 14/15 reload the whole page when pages change. Other than using a frame which would be a bit messy, I can't see a way to persist a JS object. You'll have to reconnect it each time I think if you change pages. If you are only making updates to a page, you can use AJAX updates which will preserve your websocket object. |