Nats client connection error with web sockets

1.8k Views Asked by At

I am getting problem while connecting the nats.io with web socket ? "failed to reload", how we can connect with web sockets? I think that have SSL issue but not sure about that , I have already tried many times with web sockets and socket.io but didn't get success.

import React from "react";

function App() {

  React.useEffect(() => {
    var dummy = new WebSocket("ws://localhost:4222/");
    dummy.onclose = function (e) { 
      console.log("Closed Running")
      console.log(e)
    }
    dummy.onopen = function(e) { console.log("Opened Running")}
    dummy.onmessage = function(e) { console.log(e); };
    // dummy.send("Here's some text that the server is urgently awaiting!");

  });
  return (
    <div className="App">
      <h1>Testing</h1>
    </div>
  );
}

export default App;

1

There are 1 best solutions below

0
On

The transport runs over websockets, but you still need to use the nats.ws client in order to connect as it implements the nats clients protocol.

See https://github.com/nats-io/nats.ws.