Socket.D
是基于"事件"和"语义消息""流"的网络应用层传输协议。有用户说,“Socket.D 之于 Socket,尤如 Vue 之于 Js、Mvc 之于 Http”。支持 tcp, udp, ws, kcp 传输。协议特点可参考《官网介绍》。
pyton 已开发完成,再在测试中;go, rust, c++ 正在开发中。
for Java 适配框架更新说明:
- 添加 CLOSE28_OPEN_FAIL 关闭码,优化关闭处理
- 调整 SocketD.createXxx 的异常提示,带上协议架构信息
- 调整 PathListener::of 更名为 doOf,并添加 of 函数(应用不同)
for JavaScript 适配框架更新说明:
- 完成 for Node.js server 实现!!!
- 添加 Session::remoteAddress,localAddress 方法
- 添加 CLOSE28_OPEN_FAIL 关闭码,优化关闭处理
- 调整 SocketD.createXxx 的异常提示,带上协议架构信息
- 调整 PathListener::of 更名为 doOf,并添加 of 函数(应用不同)
新增的接口体验(for Node.js Server):
现在服务端可以用 java 也可以用 node.js(很快也可以用 python 了) 。for Node.js Server Demo:
- 包配置
{
"name": "demo",
"description": "socket.d for node.js demo",
"author": "noear",
"dependencies": {
"@noear/socket.d": "2.3.9",
"ws": "^8.16.0"
}
}
- 服务端示例代码
const {
SocketD} = require('@noear/socket.d');
function main(){
let server = SocketD.createServer("sd:ws")
.config(c => c.port(8602).fragmentSize(1024 * 1024))
.listen(buildListener())
.start();
}
function buildListener() {
return SocketD.newEventListener()
.doOnOpen(s => {
console.info("onOpen: " + s.sessionId());
}).doOnMessage((s, m) => {
console.info("onMessage: " + m);
}).doOn("/demo", (s, m) => {
if