Component: WebSocket (GENERIC) (Comms: Networking)
| Author | Matrix Ltd. |
| Version | 1.0 |
| Category | Comms: Networking |
WebSocket (GENERIC) component
WebSocket server and client component designed to work with the Network Comms abstraction layer. Server mode: use CreateServerSocket to listen, then poll CheckSocketActivity to accept a browser or client connection (RFC 6455 HTTP upgrade handshake) and receive frames. Client mode: use Connect to open a link to a remote WebSocket server, then poll CheckSocketActivity to receive frames. SendText / SendBinary and the GetRx macros work identically in both modes. Frames are masked automatically in client mode. Ping, pong and close control frames are handled automatically.
Detailed description
No detailed description exists yet for this component
Examples
No additional examples
Macro reference
CheckSocketActivity
Connect
CreateServerSocket
Disconnect
| Disconnect | |
| Sends a close frame to the remote end and closes the connection. Works in both server and client mode. | |
| Return | |
GetRxByte
| GetRxByte | |
| Returns a single byte from the last received data frame payload. | |
| Index | |
| Byte index 0 to GetRxCount - 1 | |
| Return | |
GetRxCount
| GetRxCount | |
| Returns the number of payload bytes received in the last data frame (limited to Max Frame Size - 1). | |
| Return | |
GetRxOpcode
| GetRxOpcode | |
| Returns the opcode of the last received frame: 0 = Continuation, 1 = Text, 2 = Binary, 8 = Close, 9 = Ping, 10 = Pong | |
| Return | |
GetRxString
| GetRxString | |
| Returns the payload of the last received data frame as a string (up to 255 characters, use GetRxByte for larger frames or binary data). | |
| Return | |
Initialise
| Initialise | |
| Resets and initialises the WebSocket component. Defaults to server mode; calling Connect switches to client mode, CreateServerSocket switches back. | |
| Return | |
IsClientMode
| IsClientMode | |
| Returns 1 if the component is operating as a WebSocket client (after Connect), 0 if operating as a server. | |
| Return | |
IsConnected
| IsConnected | |
| Returns 1 if a WebSocket link is currently open (client connected to us in server mode, or we are connected to a server in client mode), else 0. | |
| Return | |
Ping
| Ping | |
| Sends a ping frame to the connected client. The client should reply with a pong which is consumed by CheckSocketActivity. Returns 1 if sent, 0 = not connected. | |
| Return | |
SendBinary
SendText
| SendText | |
| Sends a text frame to the connected client. Returns the number of bytes sent, 0 = not connected or failed. | |
| Data | |
| String to send | |
| Return | |
Property reference
Component Source Code
Please click here to download the component source project: FC_Comp_Source_WebSocket.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_WebSocket.fcfx