“Javascript Websocket” Kode Jawaban

JavaScript Websocket Contoh Kode

var Socket = new WebSocket('ws://' + window.location.hostname + ':81/'); // The '81' here is the Port where the WebSocket server will communicate with
// The instance of the WebSocket() class (i.e. Socket here), must need to be globally defined

Socket.send("pass your data here, and it'll be String"); // This method one can call locally
Pritam Pagla

Javascript Websocket

// npm install --save ws
const WebSocket = require('ws');

const ws = new WebSocket('ws://www.host.com/path');

ws.on('open', function open() {
  ws.send('something');
});

ws.on('message', function incoming(data) {
  console.log(data);
});
feverdreme

JS Terhubung ke Websocket

var exampleSocket = new WebSocket("wss://www.example.com/socketserver", "protocolOne");
Clear Crane

Jawaban yang mirip dengan “Javascript Websocket”

Pertanyaan yang mirip dengan “Javascript Websocket”

Lebih banyak jawaban terkait untuk “Javascript Websocket” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya