Skip to content

Releases: noear/socket.d

Socket.D v2.3.10

04 Feb 14:45
Compare
Choose a tag to compare

java 适配更新:

  • 添加 Session::closeStarting 接口(为安全退出集群提供机制)
  • 添加 关闭协议帧对 code 的支持(为安全退出集群提供机制)
  • 修复 MappedByteBuffer 不能解除映射的问题(可以改善内存与删除控制)
  • 修复 Entity.of(String) 会出错的问题
  • 修复 使用临时文件分片处理失效的问题
  • 调整 轮询最大值改为 999_999
  • 调整 消息发送锁的策略改为可配置(根据 sequenceMode 使用公平锁或非公平锁)
  • 调整 smartsocket,websocket,netty 适配的服务端线程数改由配置决定

javascript 适配更新:

  • 优化 StrUtil 关于字符转换的处理(优化使用 TextDecoder)
  • 添加 Session::closeStarting 接口
  • 添加 关闭协议帧对 code 的支持

变更示例:

安全退出集群机制

//通知要开始关闭了(集群相关方不会再发消息进来)
session.closeStarting();

//等5秒,结束正在处理的消息
sleep(5_000)

//正试关闭
session.close();

Socket.D v2.3.9

30 Jan 05:08
Compare
Choose a tag to compare

java 适配更新:

  • 无更新

javascript 适配更新:

  • 完成 for Node.js server 实现
  • 添加 Session::remoteAddress,localAddress 方法

变更示例:

for Node.js demo

  • for package.json
{
  "name": "demo",
  "description": "socket.d for node.js demo",
  "author": "noear",
  "dependencies": {
    "@noear/socket.d": "2.3.9",
    "ws": "^8.16.0"
  }
}
  • for ClientTest.js(这是之前支持的)
const {SocketD}  = require('@noear/socket.d');

async function main() {
    let clientSession = await SocketD.createClient('sd:ws://127.0.0.1:8602/?u=a&p=2')
        .config(c => c.fragmentSize(1024 * 1024))
        .listen(SocketD.newEventListener().doOnMessage((s, m) => {
            console.log('收到推送', m.dataAsString());
        }))
        .open();
    clientSession.sendAndRequest("/demo", SocketD.newEntity('hello')).thenReply(reply => {
        console.log('reply', reply);
    });
}

main();
  • for ServerTest.js(这是刚刚支持的)
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 (m.isRequest()) {
                s.reply(m, SocketD.newEntity("me to!"));
            }

            if (m.isSubscribe()) {
                let size = m.rangeSize();
                for (let i = 1; i <= size; i++ ) {
                    s.reply(m, SocketD.newEntity("me to-" + i));
                }
                s.replyEnd(m, SocketD.newEntity("welcome to my home!"));
            }
        }).doOn("/upload", (s, m) => {
            if (m.isRequest()) {
                let fileName = m.meta(SocketD.EntityMetas.META_DATA_DISPOSITION_FILENAME);
                if (fileName) {
                    s.reply(m, SocketD.newEntity("no file! size: " + m.dataSize()));
                } else {
                    s.reply(m, SocketD.newEntity("file received: " + fileName + ", size: " + m.dataSize()));
                }
            }
        }).doOn("/download", (s, m) => {
            if (m.isRequest()) {
                let fileEntity = SocketD.newEntity("...");//todo://SocketD.newEntity(fs.readFileSync("/Users/noear/Movies/snack3-rce-poc.mov"));
                s.reply(m, fileEntity);
            }
        }).doOn("/push", (s, m) => {
            if (s.attrHas("push")) {
                return;
            }

            s.attrPut("push", "1");

            for (let i = 0; i++; i < 100) {
                if (s.attrHas("push") == false) {
                    break;
                }

                s.send("/push", SocketD.newEntity("push test"));
                //todo:sleep
            }
        }).doOn("/unpush", (s, m) => {
            s.attrMap().remove("push");
        })
        .doOnClose(s => {
            console.info("onClose: " + s.sessionId());
        }).doOnError((s, err) => {
            console.warn("onError: " + s.sessionId());
        });
}

main();

Socket.D v2.3.8

23 Jan 09:33
Compare
Choose a tag to compare

java 适配更新:

  • 添加 CLOSE28_OPEN_FAIL 关闭码,优化关闭处理
  • 调整 SocketD.createXxx 的异常提示,带上协议架构信息
  • 调整 PathListener::of 更名为 doOf,并添加 of 函数(应用不同)

javascript 适配更新:

  • 添加 CLOSE28_OPEN_FAIL 关闭码,优化关闭处理
  • 调整 SocketD.createXxx 的异常提示,带上协议架构信息
  • 调整 PathListener::of 更名为 doOf,并添加 of 函数(应用不同)

变更示例:

//如果不能连接正常返回(由心跳尝试不断连接)
let session = SocketD.createClient("sd:tcp://127.0.0.1:8602/?token=1b0VsGusEkddgr3d")
        .open();

//如果不能连接则异常
let session = SocketD.createClient("sd:tcp://127.0.0.1:8602/?token=1b0VsGusEkddgr3d")
        .openOrThow();
//doOf 返回自己
new PathListener().doOf("/admin", new EventListener().doOnOpen(s->{}));

//of 返回 EventListener
new PathListener().of("/admin").doOnOpen(s->{});

Socket.D v2.3.7

21 Jan 16:38
Compare
Choose a tag to compare

java 适配更新:

  • 添加 Client::openOrThow() 方法,原 open() 不再出异常
  • 调整 ClientChannel 内部处理,支持首次连接失败后仍可用
  • 简化 ClientBase::open() 处理

javascript 适配更新:

  • 添加 Client::openOrThow() 方法,原 open() 不再出异常
  • 调整 ClientChannel 内部处理,支持首次连接失败后仍可用
  • 简化 ClientBase::open() 处理

变更示例:

//如果不能连接正常返回(由心跳尝试不断连接)
let session = SocketD.createClient("sd:tcp://127.0.0.1:8602/?token=1b0VsGusEkddgr3d")
        .open();

//如果不能连接则异常
let session = SocketD.createClient("sd:tcp://127.0.0.1:8602/?token=1b0VsGusEkddgr3d")
        .openOrThow();

Socket.D v2.3.6

15 Jan 15:37
Compare
Choose a tag to compare

java 适配更新:

  • 添加 Session::liveTime 接口
  • 添加 Entity.of 快捷方法

javascript 适配更新:

  • 添加 Session::liveTime 接口

变更示例:

//Entity.of 快捷实例构建
session.send("/demo", Entity.of("hi!"));

//最后活动时间
session.liveTime();

Socket.D v2.3.5

13 Jan 06:46
Compare
Choose a tag to compare

java 适配更新:

  • 添加 连接协议对 meta 传递的支持
  • 添加 Handshake:path 方法
  • 添加 CodecReader::peekByte 方法
  • 调啵 发送时允许实体为 null(总有不需要传的时候)
  • 优化 Codec::decodeString 处理方式

javascript 适配更新:

  • 添加 连接协议对 meta 传递的支持
  • 添加 Handshake:path 方法
  • 添加 CodecReader::peekByte 方法
  • 调啵 发送时允许实体为 null(总有不需要传的时候)
  • 优化 Codec::decodeString 处理方式

变更示例:

//连接时增加元信息传递支持
SocketD.createClient(url)
       .config(c->c.metaPut("user","xxx"))
       .open();

Socket.D v2.3.4

10 Jan 10:50
Compare
Choose a tag to compare

java 适配更新:

  • 调整 Entity:at() 更名为 Message:atName() (方便跨语言迁移)
  • 调整 sendAndRequest(timeout=-1)时,表示使用配置的流超时
  • 添加 MessageHandler 接口,方便做IOC容器组件化控制

javascript 适配更新:

  • 调整 Entity:at() 更名为 Message:atName() (方便跨语言迁移)
  • 调整 sendAndRequest(timeout=-1)时,表示使用配置的流超时
  • 完成 wx 原生接口兼容测试!!!

变更示例:

session.sendAndRequest("demo", new StringEntity(""), -1).thenReply(r->{
   //...
});

Socket.D v2.3.3

09 Jan 00:47
Compare
Choose a tag to compare

javascript 适配更新:

  • 优化 uniapp 兼容

Socket.D v2.3.2

08 Jan 16:07
Compare
Choose a tag to compare

java 适配更新:

  • 添加 range 元信息快捷方式

javascript 适配更新:

  • 添加 range 元信息快捷方式
  • 完成 uniapp(h5, android, ios) 兼容性测试
  • 完成 node.js 兼容性测试

Socket.D v2.3.0

07 Jan 02:22
Compare
Choose a tag to compare

java 适配更新:

  • 新增 SendStream,RequestStream,SubscribeStream 三个流接口。强化流接口体验
  • 添加 基于流接口,实现数据上传与下载的进度通知机制
  • 添加 基于流接口,实现异常通知机制
  • 调整 send 接口体验,基于流接口改造
  • smartsocket 升为 1.5.41

接口变化:

接口变化 描述
旧:session.send(event, entity)
新:session.send(event, entity) -> SendStream
发送
旧:session.sendAndRequest(event, entity, timeout?, callback)
新:session.sendAndRequest(event, entity, timeout?) -> RequestStream
发送并请求(要求1个答复)
旧:session.sendAndSubscribe(event, entity, timeout?, callback)
新:session.sendAndSubscribe(event, entity, timeout?) -> SubscribeStream
发送并订阅(可接收多个答复)

sendAndRequest 的同步调用改为:

session.sendAndRequest(event, entity).await();

javascript 适配更新:

  • 新增 SendStream,RequestStream,SubscribeStream 三个流接口。强化流接口体验
  • 添加 基于流接口,实现数据上传与下载的进度通知机制
  • 添加 基于流接口,实现异常通知机制
  • 调整 send 接口体验,基于流接口改造

新的接口体验(变化与 java 差不多):

//发送
session.send("/demo/hello", SocketD.newEntity("hi"));
//发送,且获取发送进度(如果有大数据发送,又需要显示进度)
session.send("/demo/upload", SocketD.newEntity(file)).thenProgress((isSend, val, max)=>{
    if(isSend){
        //获取发送进度
    }
});

//发送并请求,且同步等待
let reply = session.sendAndRequest("/demo/hello", SocketD.newEntity()).await();
//发送并请求,且取接收进度(如果有大数据获取,又需要显示进度)
session.sendAndRequest("/demo/download", SocketD.newEntity()).thenProgress((isSend, val, max)=>{
    if(!isSend){
        //获取接收进度
    }
}).thenReply(reply=>{
      //异步获取答复
}).thenError(err=>{
      //如果有出错?
});

//发送并订阅
let entity = SocketD.newEntity().metaPut("videoId","1").meatPut("start","5").meatPut("size","5");
session.sendAndSubscribe("/demo/stream", entity).thenReply(reply=>{
      //异步获取答复(会多次回调)
})