Socket.D v2.5.9

Socket.D - JavaScript 开发

</> markdown

开发,主要是对 “会话” 与 “监听器” 接口的应用组合!另外,客户端使用单连接即可:

//如果不能连接正常返回(由心跳尝试不断连接)
const session = await SocketD.createClient("sd:ws://127.0.0.1:8602/?u=a&p=2")
        .open();

//如果不能连接则异常
const session = await SocketD.createClient("sd:ws://127.0.0.1:8602/?u=a&p=2")
        .openOrThow();

目前 JavaScript 的传输适配有:

适配基础传输协议支持端安全备注支持平台
socket.d.jssd:ws, sd:wsscsslnio(41kb)浏览器, uniapp(h5, android, ios), weixin, node.js

功效:

  • 在前端接口开发时,socket.d 协议可同时可替代 http 和 ws

引用库文件或安装模块包

  • js.zip(for Browser, WebView...)

https://gitee.com/noear/socket.d/releases/download/v2.5.9/socket.d.js.zip
https://github.com/noear/socket.d/releases/download/v2.5.9/socket.d.js.zip

<script src="https://cdn.jsdelivr.net/gh/noear/socket.d@2.5.9/javascript/release/socket.d.js"></script>
<script>
//全局单例即可
const session = await SocketD.createClient("sd:ws://127.0.0.1:8602/?token=1b0VsGusEkddgr3d")
        .open();
</script>
  • js-esm.zip (for Vue, Wechat...)

https://gitee.com/noear/socket.d/releases/download/v2.5.9/socket.d.esm.js.zip
https://github.com/noear/socket.d/releases/download/v2.5.9/socket.d.esm.js.zip

import {SocketD} from "socket.d.esm"

//全局单例即可
const session = await SocketD.createClient("sd:ws://127.0.0.1:8602/?token=1b0VsGusEkddgr3d")
        .open();
  • npm(for All...)
npm install @noear/socket.d@2.5.9
// CommonJS
const {SocketD} = require("@noear/socket.d")
// ES modules
import {SocketD} from "@noear/socket.d"

//全局单例即可
const session = await SocketD.createClient("sd:ws://127.0.0.1:8602/?token=1b0VsGusEkddgr3d")
        .open()