|
| 1 | + |
| 2 | +# WebSocket Actor |
| 3 | + |
| 4 | +Authors: Andrea Vaccaro - David Grollier |
| 5 | + |
| 6 | +# Contents |
| 7 | + |
| 8 | +[1 Description [2](#description)](#description) |
| 9 | + |
| 10 | +[2 Library [2](#library)](#library) |
| 11 | + |
| 12 | +[3 Actors [2](#actors)](#actors) |
| 13 | + |
| 14 | +[3.1 WebSocket Client.lvclass |
| 15 | +[2](#websocket-client.lvclass)](#websocket-client.lvclass) |
| 16 | + |
| 17 | +[3.2 WebSocket Server Manager.lvclass |
| 18 | +[3](#websocket-server-manager.lvclass)](#websocket-server-manager.lvclass) |
| 19 | + |
| 20 | +[3.3 WebSocket Server.lvclass |
| 21 | +[3](#websocket-server.lvclass)](#websocket-server.lvclass) |
| 22 | + |
| 23 | +[3.4 WebSocket Service.lvclass |
| 24 | +[3](#websocket-service.lvclass)](#websocket-service.lvclass) |
| 25 | + |
| 26 | +[3.5 Abstract messages [4](#abstract-messages)](#abstract-messages) |
| 27 | + |
| 28 | +[3.5.1 WebSocket Connection Handler Msg.lvclass |
| 29 | +[4](#websocket-connection-handler-msg.lvclass)](#websocket-connection-handler-msg.lvclass) |
| 30 | + |
| 31 | +[3.5.2 WebSocket Server-Service Enqueuer Msg.lvclass |
| 32 | +[4](#websocket-server-service-enqueuer-msg.lvclass)](#websocket-server-service-enqueuer-msg.lvclass) |
| 33 | + |
| 34 | +[4 API [4](#api)](#api) |
| 35 | + |
| 36 | +[4.1 WebSocket Server Manager |
| 37 | +[4](#websocket-server-manager)](#websocket-server-manager) |
| 38 | + |
| 39 | +[4.1.1 WebSocket Server Listener Settings |
| 40 | +[4](#websocket-server-listener-settings)](#websocket-server-listener-settings) |
| 41 | + |
| 42 | +[4.1.2 Launch Server [4](#launch-server)](#launch-server) |
| 43 | + |
| 44 | +[4.1.3 Stop a Server [5](#stop-a-server)](#stop-a-server) |
| 45 | + |
| 46 | +[4.2 WebSocket Server [5](#websocket-server)](#websocket-server) |
| 47 | + |
| 48 | +[4.2.1 Add Service [6](#add-service)](#add-service) |
| 49 | + |
| 50 | +[4.3 WebSocket Service [7](#websocket-service)](#websocket-service) |
| 51 | + |
| 52 | +[4.3.1 Broadcast [7](#broadcast)](#broadcast) |
| 53 | + |
| 54 | +[4.3.2 Send [7](#send)](#send) |
| 55 | + |
| 56 | +[WebSocket Client [7](#websocket-client)](#websocket-client) |
| 57 | + |
| 58 | +[4.4 [7](#websocket-client)](#websocket-client) |
| 59 | + |
| 60 | +[4.5 Send to Peers [8](#send-to-peers)](#send-to-peers) |
| 61 | + |
| 62 | +# Description |
| 63 | + |
| 64 | +A library implementing a high-level actor-based implementation of |
| 65 | +WebSocket communication. An actor can subscribe to the WebSocket Actor |
| 66 | +to facilitate WebSocket-based communication. It can serve both as a |
| 67 | +client and a server. |
| 68 | + |
| 69 | +Please note that within this library **resource names** as defined in |
| 70 | +the WebSocket protocol specification are referred to as **services.** |
| 71 | + |
| 72 | +# Library |
| 73 | + |
| 74 | +<img src="./media/image1.png" style="width:3.55864in;height:3.54197in" |
| 75 | +alt="A screenshot of a computer program Description automatically generated" /> |
| 76 | + |
| 77 | +# Actors |
| 78 | + |
| 79 | +## WebSocket Client.lvclass |
| 80 | + |
| 81 | +It forwards packets received from the connected WebSocket Service to its |
| 82 | +subscriber as "WebSocket Connection Handler Msg" messages. It allows its |
| 83 | +subscriber to send data to a specified service to which the WebSocket |
| 84 | +client is connected ("Send to Peer Msg" message" message of the parent |
| 85 | +"WebSocket Connection" class). Before starting the actor, the subscriber |
| 86 | +must provide, by means of suitable properties, a data handler message in |
| 87 | +form of a concrete implementation of the "WebSocket Connection Handler |
| 88 | +Msg" abstract message used to handle the connection events corresponding |
| 89 | +to the WebSocket communication, a concrete implementation of the |
| 90 | +"WebSocket Server-Service Enqueuer Msg" abstract message used to receive |
| 91 | +the WebSocket service actor enqueuer, and the WebSocket service URI to |
| 92 | +which the client should connect. |
| 93 | + |
| 94 | +## WebSocket Server Manager.lvclass |
| 95 | + |
| 96 | +This actor's role is solely that of launching and managing the stop of |
| 97 | +"WebSocket Server" actors listening on at a specific port and interface |
| 98 | +address ("Launch Server Msg" and "Stop Server Msg" messages). The actor |
| 99 | +will ensure that the launched "WebSocket Server" doesn’t conflict on |
| 100 | +interface and port resources. If the server is already running at that |
| 101 | +port or on the specified interface the method sends just the server |
| 102 | +enqueuer to the client. If the server is not running it will be |
| 103 | +launched. |
| 104 | + |
| 105 | +## WebSocket Server.lvclass |
| 106 | + |
| 107 | +Defines a WebSocket Server characterized by an interface and a port on |
| 108 | +which it listens. Allows for the definition of WebSocket Services. |
| 109 | +Services can be defined by the server subscriber by sending the "Add |
| 110 | +Service" message to the actor. The subscriber must provide a concrete |
| 111 | +implementation of the "WebSocket Server-Service Enqueuer Msg" abstract |
| 112 | +message used to let its subscriber receive the WebSocket service actor |
| 113 | +enqueuer and a data handler message in form of a concrete implementation |
| 114 | +of the "WebSocket Connection Handler Msg" abstract message used to |
| 115 | +handle the connection events corresponding to the WebSocket |
| 116 | +communication. For each service defined a "WebSocket Service" actor is |
| 117 | +started that will send data to the subscriber that has defined the |
| 118 | +service. The actor listens according to the server specifications on a |
| 119 | +port and on an interface if not all, when a connection is established, |
| 120 | +the actor performs the WebSocket handshake. If the service requested is |
| 121 | +defined in this server, it informs the WebSocket service Actor who will |
| 122 | +start a corresponding WebSocket connection actor. If either the service |
| 123 | +is not defined, or the handshake fails, we do nothing, the WebSocket |
| 124 | +protocol will take care of communicating the failure to the client. |
| 125 | + |
| 126 | +## WebSocket Service.lvclass |
| 127 | + |
| 128 | +It forwards packets received from the connected WebSocket Clients to its |
| 129 | +subscriber actor as "WebSocket Connection Handler Msg" messages. It |
| 130 | +allows the subscriber to send data to a specified client ("Send to Peer |
| 131 | +Msg" message of the parent "WebSocket Connection" class) or to all |
| 132 | +connected clients (“Broadcast Msg” message). When launching the actor by |
| 133 | +means of the “WebSocket Server.lvclass” actor, the subscriber must |
| 134 | +provide a data handler message in form of a concrete implementation of |
| 135 | +the "WebSocket Connection Handler Msg" abstract message used to handle |
| 136 | +the connection events corresponding to the WebSocket communication and a |
| 137 | +concrete implementation of the "WebSocket Server-Service Enqueuer Msg" |
| 138 | +abstract message used to let the server subscriber actor receive the |
| 139 | +WebSocket service actor enqueuer. |
| 140 | + |
| 141 | +## Abstract messages |
| 142 | + |
| 143 | +### WebSocket Connection Handler Msg.lvclass |
| 144 | + |
| 145 | +This abstract message is sent by either the WebSocket Client or by the |
| 146 | +WebSocket Service to the subscriber Actor on four events: |
| 147 | + |
| 148 | +- Connect |
| 149 | + |
| 150 | +- Disconnect |
| 151 | + |
| 152 | +- Message |
| 153 | + |
| 154 | +- Drop |
| 155 | + |
| 156 | +For each caller Actor a concrete subclass of the message should be |
| 157 | +created by overriding the methods: |
| 158 | + |
| 159 | +- OnConnect |
| 160 | + |
| 161 | +- OnDisconnect |
| 162 | + |
| 163 | +- OnMessage |
| 164 | + |
| 165 | +- OnDrop |
| 166 | + |
| 167 | +The subscriber actor can program the required action for the |
| 168 | +corresponding event. |
| 169 | + |
| 170 | +### WebSocket Server-Service Enqueuer Msg.lvclass |
| 171 | + |
| 172 | +This abstract message is used either by the WebSocket Server Manager or |
| 173 | +by the WebSocket Server to send the just launched/added Server/Service |
| 174 | +Enqueuer to the subscriber actor requesting the operation. Each |
| 175 | +subscriber actor requesting the operation should subclass this message |
| 176 | +and then override the Do.vi in which the Server/Service Enqueuer is |
| 177 | +stored in the requesting actor. |
| 178 | + |
| 179 | +# API |
| 180 | + |
| 181 | +## WebSocket Server Manager |
| 182 | + |
| 183 | +### WebSocket Server Listener Settings |
| 184 | + |
| 185 | +<img src="./media/image2.png" style="width:1.77108in;height:1.25017in" |
| 186 | +alt="A screenshot of a computer Description automatically generated" /> |
| 187 | + |
| 188 | +**timeout ms** specifies the time, in milliseconds, that the function |
| 189 | +waits for a connection. If a connection is not established in the |
| 190 | +specified time, the function returns an error. The default value is –1, |
| 191 | +which indicates to wait indefinitely. |
| 192 | + |
| 193 | +**resolve remote address** indicates whether to call the IP To String |
| 194 | +function on the remote address. |
| 195 | + |
| 196 | +**net address** specifies on which network address to listen. Specifying |
| 197 | +an address is useful if you have more than one network card, such as two |
| 198 | +Ethernet cards, and want to listen only on the card with the specified |
| 199 | +address. If you do not specify a network address, LabVIEW listens on all |
| 200 | +network addresses. |
| 201 | + |
| 202 | +**port** is the port number on which you want to listen for a |
| 203 | +connection. |
| 204 | + |
| 205 | +### Launch Server |
| 206 | + |
| 207 | +<img src="./media/image3.png" style="width:4.77541in;height:3.16694in" |
| 208 | +alt="A screenshot of a computer Description automatically generated" /> |
| 209 | + |
| 210 | +**Message Enqueuer in** specifies the enqueuer of the WebSocket Server |
| 211 | +Manager actor. |
| 212 | + |
| 213 | +**Listener Settings** specifies the listener settings for the Server. |
| 214 | + |
| 215 | +**Handshake timeout** specifies the timeout of the handshake when the |
| 216 | +client establishes a WebSocket connection to the server. |
| 217 | + |
| 218 | +**Receive Server Enqueuer Handler** specifies the concrete message (to |
| 219 | +be created) child of the abstract message “*WebSocket Server-Service |
| 220 | +Enqueuer Msg.lvclass*”. |
| 221 | + |
| 222 | +### Stop a Server |
| 223 | + |
| 224 | +<img src="./media/image4.png" style="width:4.5754in;height:2.87525in" |
| 225 | +alt="A computer screen shot of a message Description automatically generated" /> |
| 226 | + |
| 227 | +**Subscriber Enqueuer** specifies the enqueuer of the actor that has |
| 228 | +subscribed to the previously launched WebSocket Server actor. |
| 229 | + |
| 230 | +**Message Enqueuer in** specifies the enqueuer of the WebSocket Server |
| 231 | +Manager actor to be stopped. |
| 232 | + |
| 233 | +**Listener Settings** specifies the listener settings for the previously |
| 234 | +launched WebSocket Server actor. |
| 235 | + |
| 236 | +**Handshake timeout** specifies the timeout of the handshake when the |
| 237 | +client establishes a WebSocket connection to the server. |
| 238 | + |
| 239 | +**Receive Server Enqueuer Handler** specifies the concrete message (to |
| 240 | +be created) child of the abstract message “*WebSocket Server-Service |
| 241 | +Enqueuer Msg.lvclass*”. |
| 242 | + |
| 243 | +## WebSocket Server |
| 244 | + |
| 245 | +In case the WebSocket Server Actor is manually launched the following |
| 246 | +properties are available to configure it (the port must be entered) |
| 247 | +before its launch |
| 248 | + |
| 249 | +<img src="./media/image5.png" style="width:1.81275in;height:0.55216in" |
| 250 | +alt="A close-up of a sign Description automatically generated" /> |
| 251 | + |
| 252 | +**Listener Settings** specifies the settings for the Server (see |
| 253 | +definition above). |
| 254 | + |
| 255 | +**Handshake timeout** specifies the timeout of the handshake when the |
| 256 | +client establishes a WebSocket connection to the server. |
| 257 | + |
| 258 | +### Add Service |
| 259 | + |
| 260 | +<img src="./media/image6.png" style="width:4.77541in;height:3.01693in" |
| 261 | +alt="A computer screen shot of a message Description automatically generated" /> |
| 262 | + |
| 263 | +**Receive Connection Enqueuer** specifies the concrete message (to be |
| 264 | +created) child of the abstract message “*WebSocket Server-Service |
| 265 | +Enqueuer Msg.lvclass”.* |
| 266 | + |
| 267 | +**Message Enqueuer in** specifies the enqueuer of the WebSocket Server |
| 268 | +actor. |
| 269 | + |
| 270 | +**Service Name** specifies the name of the service. |
| 271 | + |
| 272 | +**Subscriber Enqueuer** specifies the enqueuer of the actor (to be |
| 273 | +created) that subscribes to the WebSocket Server Actor. |
| 274 | + |
| 275 | +**WebSocket Data Handler** specifies the concrete message (to be |
| 276 | +created) child of the abstract message “*WebSocket Connection Handler |
| 277 | +Msg.lvclass”.* |
| 278 | + |
| 279 | +## WebSocket Service |
| 280 | + |
| 281 | +### Broadcast |
| 282 | + |
| 283 | +<img src="./media/image7.png" style="width:4.17536in;height:2.16685in" |
| 284 | +alt="A screen shot of a computer Description automatically generated" /> |
| 285 | +**Message Enqueuer in** specifies the enqueuer of the WebSocket Service |
| 286 | +actor. |
| 287 | + |
| 288 | +**Data** specifies the data to be sent. |
| 289 | + |
| 290 | +### Send |
| 291 | + |
| 292 | +<img src="./media/image8.png" style="width:4.14203in;height:2.34187in" |
| 293 | +alt="A computer screen shot of a message Description automatically generated" /> |
| 294 | + |
| 295 | +**Message Enqueuer in** specifies the enqueuer of the WebSocket Service |
| 296 | +actor. |
| 297 | + |
| 298 | +**Data** specifies the data to be sent. |
| 299 | + |
| 300 | +**Client ID** ID that identifies the specific WebSocket client to which |
| 301 | +we want to send the data |
| 302 | + |
| 303 | +## WebSocket Client |
| 304 | + |
| 305 | +The following properties of the WebSocket Client actor must be set |
| 306 | +before launching it: |
| 307 | + |
| 308 | +<img src="./media/image9.png" style="width:1.79167in;height:0.91667in" |
| 309 | +alt="A screenshot of a computer Description automatically generated" /> |
| 310 | + |
| 311 | +**WS URI** specifies the URI of the client with the following format: |
| 312 | + |
| 313 | +*ws://hostname:port/service* |
| 314 | + |
| 315 | +**Timeout (ms)** is the timeout to establish the connection to the |
| 316 | +server. A value of –1 indicates to wait indefinitely. |
| 317 | + |
| 318 | +**WebSocket Data Handler** specifies the concrete message (to be |
| 319 | +created) child of the abstract message “*WebSocket Connection Handler |
| 320 | +Msg.lvclass”.* |
| 321 | + |
| 322 | +**Subscriber Enqueuer** specifies the enqueuer of the actor (must be |
| 323 | +created) that subscribes to the WebSocket Client Actor. |
| 324 | + |
| 325 | +## Send to Peers |
| 326 | + |
| 327 | +<img src="./media/image10.png" style="width:4.20036in;height:2.6419in" |
| 328 | +alt="A computer screen shot of a message Description automatically generated" /> |
| 329 | + |
| 330 | +**Message Enqueuer in** specifies the enqueuer of the WebSocket Client |
| 331 | +actor. |
| 332 | + |
| 333 | +**Data Format (Text)** Specifies an Enum allwing top specify if the data |
| 334 | +format is either “Text” or “Binary”. |
| 335 | + |
| 336 | +**Timeout ms** (5000) is the timeout to establish the connection to the |
| 337 | +server. A value of –1 indicates to wait indefinitely. |
0 commit comments