Get Example source ABAP code based on a different SAP table
ABAP_APC - AS ABAP as WebSocket Client This example demonstrates AS ABAP as a WebSocket client.
ABAP_SOURCE_CODE DEMO CL_DEMO_APC_CLIENT
ABAP_DESCRIPTION This example demonstrates how an ABAP program can create an APC client> for the WebSocket protocol.
The local class apc_handler>, which implements the interface IF_APC_WSP_EVENT_HANDLER_PCP>>, is used as the handler class. When a message is received, the method on_message> sets its message> attribute to the message text.
CL_APC_WSP_CLIENT_MANAGER>> is used to create a client object for the current AS ABAP as an APC server and opens a connection to one of its ABAP push channels. It is possible to select which of the two ABAP push channels, DEMO_APC_PCP> or DEMO_APC_PCP_STATEFUL>, from the executable example AS ABAP as WebSocket Server> is used. The server can also be instructed to send its messages using ABAP messaging channels>.
The message manager of the client object is used to create a message in PCP format> and send it multiple times.
The statement WAIT FOR PUSH CHANNELS>> is then used to switch the execution to a wait state so that messages sent back from the server can be handled. Here, the logical expression checks the attribute message > of the handler class apc_handler>. A received text is displayed.
Finally, the connection is closed explicitly. It is possible to select how many messages are sent and how often the wait state occurs.
If communication takes place with the stateful server, the counter level of the server is raised, when multiple messages are sent and received.
If the server sends its messages using ABAP messaging channels, other AMC receivers in the same messaging channel can also see the messages of the server. For example, the Web browser from the executable example AS ABAP as WebSocket Server> can receive these messages. In the reverse direction, the APC client can then also receive those messages sent by the APC server as a response to messages from the Web browser, if they occur in one of the programmed wait periods.