picyka Posted August 18, 2022 Share Posted August 18, 2022 Bom dia, quem está procurando uma solução para socket, Eu recomendo https://github.com/mateusvicente100/bird-socket-server muito simples de usar Lembrando que o servidor de soquete deve ser separado do UNIGUI Cliente: class procedure TUniGUISocket.Connect(Main: TUniForm); begin var ServidorURL := 'ws://' + Self.GetServidor; var SocketName := 'ws_' + Main.WebForm.JSName; var lScript := ' try { ' + ' uniVars.' + SocketName + ' = new ReconnectingWebSocket("' + ServidorURL + '"); ' + ' uniVars.' + SocketName + '.addEventListener(''message'', function (event){ajaxRequest(' + Main.WebForm.JSName + ', "_socket", [''text='' + event.data]);}) ' + ' } ' + ' catch (e) { ' + ' console.log(''error socket open: '', e) ' + ' };'; Main.UniSession.AddJS(lScript); end; class procedure TUniGUISocket.Disconnect(Main: TUniForm); begin var ServidorURL := 'ws://' + Self.GetServidor; var SocketName := 'ws_' + Main.WebForm.JSName; var lScript := ' try { ' + ' uniVars.' + SocketName + '.close() ' + ' } ' + ' catch (e) { ' + ' console.log(''error socket close: '', e) ' + ' };'; Main.UniSession.AddJS(lScript); end; class procedure TUniGUISocket.ProcessMessage(Main: TUniForm; _Mensagem: String); begin if _Mensagem = _NEW_VERSION then begin if TMessageUtils.Question('A uma nova versão disponível, para evitar qualquer instabilidade é necessário atualizar.' + sLineBreak + '<b>Deseja atualizar agora?</b>', 'Atenção') = mrYes then begin UniSession.Logout; UniApplication.Restart; end; end else if _Mensagem = _NEW_AUTH then TMainForm(Main).UniTimerRecoonectSocket.Enabled := True else if _Mensagem = _LOGIN_SUCESS then TMainForm(Main).UniTimerRecoonectSocket.Enabled := False; end; class procedure TUniGUISocket.Send(Main: TUniForm; Value: String); begin var ServidorURL := 'ws://' + Self.GetServidor; var SocketName := 'ws_' + Main.WebForm.JSName; var lScript := ' try { ' + ' uniVars.' + SocketName + '.send(''' + Value + ''') ' + ' } ' + ' catch (e) { ' + ' console.log(''error socket send: '', e) ' + ' };'; Main.UniSession.AddJS(lScript); end; Só para contribuir com a comunidade. Sobre o cliente que eu estou usando GitHub - joewalnes/reconconnecting-websocket: Um pequeno decorador para a API JavaScript WebSocket que se reconecta automaticamente Reconectando o WebSocket espero que seja útil para alguém, Hugs. 1 1 Quote Link to comment Share on other sites More sharing options...
Wilton Ergon Posted August 23, 2022 Share Posted August 23, 2022 We are about to receive the version of unigui with native websockets, any external solution, in my opinion, is a waste of time. this project was created by a brazilian from the same team as horse. for other uses it is very good and works well 1 Quote Link to comment Share on other sites More sharing options...
picyka Posted August 24, 2022 Author Share Posted August 24, 2022 14 horas atrás, Wilton Ergon disse: Estamos prestes a receber a versão do unigui com websockets nativos, qualquer solução externa, na minha opinião, é uma perda de tempo. este projeto foi criado por um brasileiro da mesma equipe que o cavalo. para outros usos é muito bom e funciona bem Good morning, I use 3 layers, so the socket server was out of unigui, by the tests I did it works. Note: It's still in testing, when it comes out native in unigui, I can change it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.