相关文章推荐
打盹的课本  ·  The WebSocket API ...·  4 月前    · 
酒量小的墨镜  ·  Spring Framework 4.0 ...·  2 月前    · 
霸气的麦片  ·  20. WebSocket Support·  1 月前    · 
魁梧的黑框眼镜  ·  33. WebSockets Support·  1 月前    · 
安静的西装  ·  新闻资讯·  11 月前    · 
逃课的小虾米  ·  Xie Qinghua Home ...·  1 年前    · 
没人理的帽子  ·  c++ - How to read a ...·  2 年前    · 

Enqueues data to be transmitted.

Events

Listen to these events using addEventListener() or by assigning an event listener to the oneventname property of this interface.

close
Fired when a connection with a WebSocket is closed. Also available via the onclose property
error
Fired when a connection with a WebSocket has been closed because of an error, such as when some data couldn't be sent. Also available via the onerror property.
message
Fired when data is received through a WebSocket . Also available via the onmessage property. Fired when a connection with a WebSocket is opened. Also available via the onopen property.

Examples

js

// Create WebSocket connection.
const socket = new WebSocket("ws://localhost:8080");
// Connection opened
socket.addEventListener("open", (event) => {
  socket.send("Hello Server!");
});
// Listen for messages