You can use the following sample code, it opens a connection to localhost server listening port 5414.
When connects to server, sends the message "Message from react".
import React, { Component } from 'react';
export class sgcWebSockets extends Component {
static displayName = sgcWebSockets.name;
this.ws.onopen = () => {
// connected
this.ws.send('Message from react')
}
this.ws.onmessage = evt => {
// listen to data sent from the websocket server
const message = JSON.parse(evt.data)
}