Advertisement
peterphonic

wss client jaavascript

Feb 10th, 2023
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   const options = {
  2.       ca: fs.readFileSync("./ca.crt"),
  3.     };
  4.    
  5.     var client = new WebSocketClient();
  6.    
  7.     client.on("connectFailed", function (error) {
  8.       console.log("Connect Error: " + error.toString());
  9.     });
  10.    
  11.     client.on("connect", function (connection) {
  12.       console.log("WebSocket Client Connected");
  13.       connection.on("error", function (error) {
  14.         console.log("Connection Error: " + error.toString());
  15.       });
  16.       connection.on("close", function () {
  17.         console.log("echo-protocol Connection Closed");
  18.       });
  19.       connection.on("message", function (message) {
  20.         if (message.type === "utf8") {
  21.           console.log("Received: '" + message.utf8Data + "'");
  22.         }
  23.       });
  24.    
  25.     });
  26.     client.connect("wss://192.168.230.138:8080/", null, null, null, options);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement