I'm currently working on a ABAP Push Channel on TCP Socket and I create a connection between the SAP ABAP System und the extern device.
The problem that my ABAP Push Channel can't receive or show the response from the device with error Timeout occurred!, but this is not the case when I use the ncat
Here is the code:
PARAMETERS: host TYPE string DEFAULT 'xxx.xxx.xxx.xxx', " ip adress reciever
port TYPE string DEFAULT '11300',
"text TYPE string DEFAULT 'GET /outputaccess0?PW=Intecio!&State=ON&' LOWER CASE,
kommand(1) AS LISTBOX VISIBLE LENGTH 10.
DATA text TYPE string.
AT SELECTION-SCREEN OUTPUT.
TYPE-POOLS: vrm.
DATA:
name TYPE vrm_id,
list TYPE vrm_values,
value TYPE vrm_value.
name = 'KOMMAND'. " Name should be in UPPER CASE
value-key = '1'.
value-text = 'Test1'.
APPEND value TO list.
value-key = '2'.
value-text = 'test2'.
APPEND value TO list.
value-key = '3'.
value-text = 'Test3'.
APPEND value TO list.
value-key = '4'.
value-text = 'est4'.
APPEND value TO list.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = name
values = list
EXCEPTIONS
id_illegal_name = 0
OTHERS = 0.
INITIALIZATION.
host = cl_gui_frontend_services=>get_ip_address( ).
"CONCATENATE '11' '300' INTO port.
DATA terminator TYPE string.
CLASS apc_handler DEFINITION FINAL .
PUBLIC SECTION.
INTERFACES if_apc_wsp_event_handler.
DATA message TYPE string.
ENDCLASS.
"Step 2: Implement event handler to get events (on_start, on_message, on_close)
CLASS apc_handler IMPLEMENTATION.
METHOD if_apc_wsp_event_handler~on_open .
"message = 'Connection opned!'.
ENDMETHOD.
METHOD if_apc_wsp_event_handler~on_message.
TRY.
message = i_message->get_text( ).
DATA(lo_message) = i_message_manager->create_message( ).
"Cut of '0A' terminator
DATA(len) = strlen( message ) - 1.
message = message(len).
"message = 'TEST'.
CATCH cx_apc_error INTO DATA(apc_error).
message = apc_error->get_text( ).
ENDTRY.
ENDMETHOD.
METHOD if_apc_wsp_event_handler~on_close.
message = 'Connection closed!'.
ENDMETHOD.
METHOD if_apc_wsp_event_handler~on_error.
message = 'Connection interrupted !!'.
ENDMETHOD.
ENDCLASS.
CLASS apc_demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS apc_demo IMPLEMENTATION.
METHOD main.
IF kOMMAND = 1.
text = 'Kommand1'.
ELSEIF KOMMAND = 2.
text = 'Kommand2'.
ELSEIF KOMMAND = 3.
text = 'Kommand3'.
ELSEIF KOMMAND = 4.
text = 'ommand4'.
ELSE.
text = 'test'.
ENDIF.
TRY.
"Create event handler
DATA(event_handler) = NEW apc_handler( ).
"Step 1: specify TCP frame information
terminator = `0A`.
DATA client TYPE REF TO if_apc_wsp_client.
"Step 3: create TCP client object and connect it to server
client = cl_apc_tcp_client_manager=>create(
i_host = host
i_port = port
i_frame = VALUE apc_tcp_frame(
frame_type =
if_apc_tcp_frame_types=>co_frame_type_terminator
terminator =
terminator )
i_event_handler = event_handler ).
client->connect( ).
"Send initial 'hello' message from client
DATA(message_manager) = CAST if_apc_wsp_message_manager(
client->get_message_manager( ) ).
DATA(message) = CAST if_apc_wsp_message(
message_manager->create_message( ) ).
DATA(binary_terminator) = CONV xstring( terminator ).
DATA(binary_msg) = cl_abap_codepage=>convert_to( text ).
CONCATENATE binary_msg binary_terminator
INTO binary_msg IN BYTE MODE.
message->set_binary( binary_msg ).
message_manager->send( message ).
"Step 4: Wait for incoming messages from server
CLEAR event_handler->message.
WAIT FOR PUSH CHANNELS
UNTIL event_handler->message IS NOT INITIAL UP TO 5 SECONDS.
IF sy-subrc = 4.
WRITE: 'No handler for APC messages registered!' .
ELSEIF sy-subrc = 8.
WRITE: 'Timeout occured!'.
ELSE.
WRITE: 'TCP client received: '.
WRITE: event_handler->message.
ENDIF.
client->close( i_reason = 'Application closed connection!' ).
CATCH cx_apc_error INTO DATA(apc_error).
WRITE: apc_error->get_text( ).
ENDTRY.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
apc_demo=>main( ).