15 Şubat 2021 Pazartesi

WebSocket Sınıfı

constructor
Şöyle yaparız
// Create a new WebSocket
let socketConnection = new WebSocket('ws://websocket.mysite.com');
constructor - subprotocol
Şöyle yaparız
// Create a new WebSocket with subprotocols
let socketConnection = new WebSocket('ws://websocket.mysite.com', ['soap', 'xmpp']);
onX metodu
Şöyle yaparız
// When the connection is open, some data is sent to the server
socketConnection.onopen = function () {
  connection.send('Hello, the socket connection is open!'); // Send a message to the server
};

// Log errors
socketConnection.onerror = function (error) {
  console.log('WebSocket Error ' + error);
};

// Log messages from the server
socketConnection.onmessage = function (e) {
  console.log('Server: ' + e.data);
};


Hiç yorum yok:

Yorum Gönder