Loading...
 

CX_WIDGET::PushSocket

CX_WIDGET::PushSocket

189117

Description:

If the widget on which this method is called is a web widget and is connected to a MorphIT client, PushSocket can be used to send any message to the corresponding web widget in the browser.

If the widget has not yet been opened in the browser, the message will be lost without warning. Therefore, make sure that the web widget really exists and is ready before a message is sent to the widget via PushSocket. The easiest way to ensure this is to use PushSocket only within _SOCKET messages, in response to a request from the web widget. (As also shown in the code example).

The message type, which is passed at PushSocket, is used to categorize the messages. The Web widget receives the transferred data and the type. If the web widget sends a message to the ClassiX system, this message is converted into a message by converting the type to upper case and appending a _SOCKET. Thus, a fetch_data becomes FETCH_DATA_SOCKET. The data is then placed on the stack. The data is converted from JSON format to a compatible ClassiX type.

All data types that are also accepted by CX_JSON_PARSER::WriteToString (i.e. all types that can be easily translated into a JSON value) are permitted as data to be transmitted.

PushSocket is an asynchronous call that returns immediately. The sending of the message is delayed and there is no guarantee when exactly the web widget will receive the message. There is only a guarantee that when multiple PushSocket calls are made, the web widget receives the messages in the same order.

Code example:
Web(webWidget, APP("QM/widget.html"), 10, 25, 700, 200) [ FETCH_DATA_SOCKET: Drop //Ignore passed data from web widget Var(json) CreateTransObject(CX_JSON_OBJECT) -> json "value" "key" json Call(PutTyped) json "response" Widget Call(PushSocket) //Push data to socket as message of type "response" ]
Stack
Stack Positionn Object type Brief description
Stack(In) Top CX_WIDGET A widget
top one STRING The message type
top two JSON type The data to be transmitted
Stack(Out) Top
Function call: Call(PushSocket)