Client sample
Using the WebSocket-client sample bundle
The WebSocket-client sample bundle in samples/websocket-client shows how to set up a simple WebSocket client that will ping a server every second.
Prerequisites
- Working NodeCG & nodecg-io installation
For simplicity's sake this sample will rely upon the websocket-server sample.
Configure the WebSocket-client sample bundle
Please set up the WebSocket-server bundle first and then follow these steps:
-
Start nodecg with nodecg-io installed. The websocket-client bundle is currently part of it so it should also be loaded.
-
Go to the
nodecg-iotab in the nodecg dashboard. -
Login using your password. If this is your first run, then enter the password with which you want to encrypt your configurations and credentials.
-
Create a new ws-client service instance using the left upper menu.
-
Enter the address of the sample server. This has to be a url following the pattern
ws://localhost:<port>.The created instance should be automatically selected, if not select it in the upper left menu. Enter your port in monaco (the text-editor on the right) in this format:
{ "address": "ws://localhost:7777" }After entering it, click save.
-
Set the created ws-client service instance to the service dependency of the ws-client bundle.
-
A websocket-client has been connected and the console should display if a ping is sent or a pong is received.