#1 2023-12-13 19:11:29

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Using Async Socket to Refresh Client

Hi Ab, is there a simple Solution to this Idea:

Lets say i have 10(or more) client showing data from my Server received with some SOA Calls.
Now one of the clients does some updates on the data and sends it to the server, using SOA - Update call.

Now i like the Server to inform the Client about data changes, to display the changed data.
I don't like to pull the Data every 5s from the client.
i like to have a kind of Push message from the Server to the clients interested in this message.

The Client could also be a Webseite using WebSockets.

Is it possible to use the same port as the SOA Server for the Socket Server or do i need a second port ?

i read this: https://blog.synopse.info/?post/2022/05 … n-mORMot-2

Last edited by itSDS (2023-12-13 19:15:03)


Rad Studio 12.1 Santorini

Offline

#2 2023-12-13 19:46:45

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: Using Async Socket to Refresh Client

I think i can solve it with the Samples from m2: ex/rest-websockets.

Last edited by itSDS (2023-12-13 19:46:55)


Rad Studio 12.1 Santorini

Offline

#3 2023-12-13 20:16:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Using Async Socket to Refresh Client

You just need to use a single mORMot WebSockets-capable server on the port.

It would be able to solve regular request/answer REST SOA calls over HTTP, and being able to upgrade as WebSockets if needed, for SOA calls with interface callbacks.

Offline

#4 2023-12-18 12:05:55

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: Using Async Socket to Refresh Client

Hi i have implemented a client Server for windows now. And the next step is to be notified on a Webpage using WebSocket

i tried it but WebSocket does not connect. So created a litte sample for your restws_chatserver.exe. But also can not connect.
Is there a sample on how to connect to that kind of WebSocket from JavaSript/html ?

I like to do something similar as with the ChatClient
Calling Join Funktion and receive the Chat in the Callback.

Sample (copied from : SimpleEchoServer - mormot1) but here i try to connect to Chatserver.

function init(){
  try
  {
    socket = new WebSocket("ws://localhost:8888/root/","synopsebin");
    log('WebSocket - status '+socket.readyState);
    socket.onopen    = function(msg){
		console.log(msg); 
		log("onopen: Welcome - status "+this.readyState); 
	};
    socket.onmessage = function(msg){ 
		console.log(msg); 
		log("onmessage: ("+msg.data.length+" bytes): " + (msg.data.length < 5000 ? msg.data : (msg.data.substr(0, 30) + '...'))); 
	};
    socket.onerror   = function(msg){ 
		console.log(msg); 
		log("onerror - code:" + msg.code + ", reason:" + msg.reason + ", wasClean:" + msg.wasClean + ", status:" + this.readyState); 
	};
    socket.onclose   = function(msg){ 
		console.log(msg); 
		log("onclose - code:" + msg.code + ", reason:" + msg.reason + ", wasClean:" + msg.wasClean + ", status:" + this.readyState); 
	};
  }
  catch(ex)
  {
    log(ex);
  }
  $("msg").focus();
}

ty

Last edited by itSDS (2023-12-18 12:10:45)


Rad Studio 12.1 Santorini

Offline

#5 2023-12-18 18:30:48

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: Using Async Socket to Refresh Client

Hi Arnaud,, forget my last question, i read in other posts in the forum that the callback like approach will not work with WebSockets.
I'll do it in a different way smile


Rad Studio 12.1 Santorini

Offline

#6 2023-12-19 03:26:12

Chaa
Member
Registered: 2011-03-26
Posts: 248

Re: Using Async Socket to Refresh Client

In JavaScript you need to use "synopsejson" protocol (in WebSocket constructor).

Offline

Board footer

Powered by FluxBB