UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21. Read more.
UPDATE! The community will be go into read-only on April 19, 8am Pacific in preparation for migration on April 21.Read more.
Cadet 3rd Class
Cadet 3rd Class
278 views

Using web_websocket_send in async way?

Hi everyone!

Is it possible to use web_websocket_send in async way for Polling?

I need async using of websockets for implementing custom heartbeat:

  1. every 30 seconds clients send a string with custom heartbeat to the server
  2. the server doesn't respond anything when receives a heartbeat.

I cant use lr_think_time(30) because I have many HTML requests from client which should be parallel with websocket's heartbeats.

 

Is it possible to use web_reg_async_attributes with web_websocket_send?

Labels (2)
5 Replies
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Hi @Xgdsf1 

 

web_reg_async_attributes requires an "URL".

But  web_websocket_send is based on an connected connection.

I don't think it works.

 

I understand that you just need a "Timer".

There's a workaround can be tried.

You can call web_reg_async_attributes for another available URL, and make the "RequestCB"  trigger the  web_websocket_send. So it can work as a "Timer"

Sample code:

int Poll_RequestCB()
{

    //Send your websocket buffer here
    web_websocket_send("ID=0", 
        ..., 
        LAST);
    
    return WEB_ASYNC_CB_RC_OK;
}

Action()
{

    web_websocket_connect("ID=0", 
       ..., 
        LAST);

    web_reg_async_attributes("ID=AsTimer", 
        "URL=http://<AnotherAvailableHTTPURL>", 
        "Pattern=Poll", 
        "PollIntervalMs=30000", //30 seconds
        "RequestCB=Poll_RequestCB", 
        LAST);
    
    web_url("web_url",
        "URL=http://<AnotherAvailableHTTPURL>",
        "TargetFrame=",
        "Resource=0",
        "Referer=",
        LAST);

     //Other steps
     ...
     ...
    
     web_websocket_close("ID=0", 
        ...,
        LAST);

    return 0;
}

 

Another workaround is that Web/HTTP protocol supports not only C but also JS.

Maybe you can find some JS functions to do it.(I mean timer)

 

Regards,

Wei-Wei Zhang

Cadet 3rd Class
Cadet 3rd Class

Thank you!
Is it okey to start Polling in vuser_init action and finish it in vuser_end putting there web_stop_async?
Cadet 3rd Class
Cadet 3rd Class

LR User Guide says that Async conversations continues until web_stop_async or until the end of iteration.

So If I put Polling in vuser_init it will be stopped at the end of first iteration. Is there any workaround to continue Polling through all iterations until vuser_end execution?

Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Hi @Xgdsf1 

As I remember all the connections will be closed by the end of iteration.

I looks like no workaround to make async connections cross iteration.

BTW, there's pacing time during iterations, so I don't think async timer can work as expected even there's a magic to make it cross iteration.

 

Regards,

Wei-Wei Zhang

0 Likes
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

If you just want to make async cross "vuser_init" and "Action", the answer is "Yes".

Please find "Simulate a new user on each iteration" in RTS and check off it.

Then make the script like

vuser_init  <- add  web_reg_async_attributes  web_url web_websocket_connect and  Poll_RequestCB for  web_websocket_send here.

Action1 <- you will find Poll_RequestCB can still be triggerred in Action1

Action2 <- you will find Poll_RequestCB can still be triggerred in Action2

...

vuser_end <-add  web_stop_async and  web_websocket_close here.

 

But if you want to make async cross iterations, the answer looks like "No".

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.