Thumbnail

Websocket Client

A client to send and receive data to a WebSocket.

+ How To Add This Control To Your Project (Click to Expand)
  1. Make sure you have the latest version of ARC installed.
  2. Select the Get button in this page to download the archive file.
  3. Double click the downloaded archive file to execute installer.
  4. The installer will add this control to ARC.
  5. Load ARC and press the Project -> Add Control button from the menu.
  6. Choose the Communication category tab.
  7. Press the Websocket Client icon to add the control to your project.

Manual

A client to send and receive data to a WebSocket, assign the response to a variable, and execute scripts.

User-inserted image


Use ControlCommand to open a connection to a remote host and send data. The received data will be assigned to a variable and the specified script will execute. Once a connection is established to the server using the ControlCommand Open, your program may now send messages to the server via the ControlCommand Send. Any messages received from the server are stored in a variable and the script is launched. 

User-inserted image



Configuration Menu
User-inserted image



1) The Response Variable will hold the text response message that is sent from the server.

2) Response Script will be executed for every response that is sent from the server. Within this script, the response message is available in the Response Variable. By default, an example script will speak the response data.

3) The Connection Status Variable holds a true or false bool regarding the status of the connection to the server.

4) Enable Debug will display the full response message in the log window. This will consume unnecessary CPU and memory in a production environment and is only for debugging. By default, this is checked.


Open Connection
This example command will create a connection to the public WebSocket echo server for testing. Any data sent to this web socket server will be echoed back.

Code:

ControlCommand("WebSocket Client", "Open", "ws://echo.websocket.org");

Send Data
Send test data once the connection has been established. You can continually send data as needed. When data is received from the server, the response will be assigned to a variable and the script will execute. By default, the script will speak the response.

Code:

ControlCommand("WebSocket Client", "Send", "Text to send");

PRO
Canada
#1  
Could you please provide an option to disable the Voice reading of the variables.  Thanks
PRO
Synthiam
#2   — Edited
Default script is to speak the variable when the robot skill is first added.
User-inserted image



However, it is something you can easily change. ARC robot skills have config buttons for configuring settings. Follow these steps...

1) Load ARC

2) add this robot skill

3) press the config button on this robot skill (it’s three little dots next to the close and help)
User-inserted image


4) press the Response Script button (This script is executed for every response message received from the server)
User-inserted image


5) change the default code or remove it. This is a necessary step because you’ll always need to handle incoming messages.
User-inserted image


6) Press SAVE to save the project with the configured skill
PRO
Canada
#3  
Thanks DJ, I missed that. Web socket will be very useful for doing a lot of things. Nice skill.
PRO
Canada
#4  
I just downloaded latest version but it no longer appears to work. Example if I just connect to a test server, I get an error it can no longer send. 
ControlCommand("WebSocket Client", "Open", "ws://demos.kaazing.com/echo");
ControlCommand("WebSocket Client", "Send", "{'test'}");

Start
ControlCommand Error for 'WebSocket Client' sending 'send'. Not connected
Done (00:00:00.0091077)
PRO
Synthiam
#5   — Edited
Maybe try putting some time to let the connection actually happen. Web sockets are a little weird that way...

Code:


ControlCommand("WebSocket Client", "Open", "ws://echo.websocket.org");
sleep(1000)
ControlCommand("WebSocket Client", "Send", "{'test'}");
PRO
Canada
#6  
OK I was using two seperate scripts funny that websocket.org worked but not that one or my dog.  strange
PRO
Synthiam
#7  
I'll make the OPEN wait until the connection is either completed or times out. I'll post an update - stay tuned
PRO
Synthiam
#8  
Updated to not require a sleep after connecting. It will internally wait for the connection or throw a timeout error
PRO
Canada
#9  
ok getting data again. Thanks.  Still haven't gotten it to actually accept a command yet but one step forward
PRO
Synthiam
#10  
Bugfix when a message is received while ARC is closing