logo
  • 教程列表
  • SO官方文檔
  • HTTP 請求
    • 使用帶有 fetch API 和 Redux 的 Promise
    • 使用 fetch API 的 HTTP
    • 與 XMLHttpRequest 聯網
    • WebSockets
    • 與 axios 的 Http
    • Web 套接字與 Socket.io
  1. StackOverflow 文件
  2. react-native 教程
  3. HTTP 請求
  4. WebSockets

WebSockets

Created: November-22, 2018

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

ws.onopen = () => {
  // connection opened

  ws.send('something'); // send a message
};

ws.onmessage = (e) => {
  // a message was received
  console.log(e.data);
};

ws.onerror = (e) => {
  // an error occurred
  console.log(e.message);
};

ws.onclose = (e) => {
  // connection closed
  console.log(e.code, e.reason);
};
  • 與 axios 的 Http
  • 與 XMLHttpRequest 聯網

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明