sgcWebSockets and React client

sgcWebSockets library fully supports RFC6455, so any client that supports this RFC will be able to connect to our servers.

You can connect with REACT to sgcWebSockets library without problems, just create a new class which implements WebSocket class and use it to connect, send messages, receive messages from server...

React WebSocket Example

 In order to use WebSocket protocol in React, you must use instantiate WebSocket class, passing websocket url as argument (example: ws:// and then bind websocket events to be notified when socket is connected, disconnected or a new message arrives. Find below a very simple sample react code, which shows how connect to a websocket server and send a message after a successful connection.

import React, { Component } from 'react';

export class sgcWebSockets extends Component {
    static displayName =;

    constructor(props) {
        super(props); = WebSocket
        this.websocketOpen = this.websocketOpen.bind(this);

    websocketOpen() { = new WebSocket('ws://localhost:5414') = () => {
            // connected
  'Message from react')
        } = evt => {
            // listen to data sent from the websocket server
            const message = JSON.parse(
        } = () => {
            // disconnected

    render() {
        return (
                <button className="btn btn-primary" onClick={this.websocketOpen}>Connect</button>

ASP.NET Core React Example 

 You can build React Apps using ASP .NET Core, find below a link to download a full Visual Studio Project, showing a demo that connects to our secure websocket server chat.

Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Google Cloud Pub/Sub Delphi Component

Related Posts