基于事件和語義消息流的網(wǎng)絡應用層協(xié)議。
有用戶說,“Socket.D 之于 Socket,尤如 Vue 之于 Js、Mvc 之于 Http”。支持 tcp, udp, ws, kcp 傳輸。文章來源:http://www.zghlxwxcb.cn/news/detail-788654.html
主要特性
- 基于事件,每個消息都可事件路由
- 所謂語義,通過元信息進行語義描述
- 流關聯(lián)性,來回相關的消息會串成一個流
- 語言無關,使用二進制輸傳數(shù)據(jù)(支持 tcp, ws, udp)。支持多語言、多平臺
- 斷線重連,自動連接恢復
- 多路復用,一個連接便可允許多個請求和響應消息同時運行
- 雙向通訊,單鏈接雙向互聽互發(fā)
- 自動分片,數(shù)據(jù)超出 16Mb(大小可配置),會自動分片、自動重組(udp 除外)
- 接口簡單,是響應式但用回調接口
Java 適配更新(兼容 server 與 android):
- 新增 SendStream,RequestStream,SubscribeStream 三個流接口。強化流接口體驗
- 添加 基于流接口,實現(xiàn)數(shù)據(jù)上傳與下載的進度通知機制
- 添加 基于流接口,實現(xiàn)異常通知機制
- 調整 send 接口體驗,基于流接口改造
- smartsocket 升為 1.5.41
接口變化 | 描述 |
---|---|
舊:session.send(event, entity) 新: session.send(event, entity) -> SendStream
|
發(fā)送 |
舊:session.sendAndRequest(event, entity, timeout?, callback) 新: session.sendAndRequest(event, entity, timeout?) -> RequestStream
|
發(fā)送并請求(要求1個答復) |
舊:session.sendAndSubscribe(event, entity, timeout?, callback) 新: session.sendAndSubscribe(event, entity, timeout?) -> SubscribeStream
|
發(fā)送并訂閱(可接收多個答復) |
Javascript 適配更新(兼容 h5, uniapp, node.js):
- 新增 SendStream,RequestStream,SubscribeStream 三個流接口。強化流接口體驗
- 添加 基于流接口,實現(xiàn)數(shù)據(jù)上傳與下載的進度通知機制
- 添加 基于流接口,實現(xiàn)異常通知機制
- 調整 send 接口體驗,基于流接口改造
//發(fā)送
session.send("/demo/hello", SocketD.newEntity("hi"));
//發(fā)送,且獲取發(fā)送進度(如果有大數(shù)據(jù)發(fā)送,又需要顯示進度)
session.send("/demo/upload", SocketD.newEntity(file)).thenProgress((isSend, val, max)=>{
if(isSend){
//獲取發(fā)送進度
}
});
//發(fā)送并請求,且同步等待
let reply = session.sendAndRequest("/demo/hello", SocketD.newEntity()).await();
//發(fā)送并請求,且取接收進度(如果有大數(shù)據(jù)獲取,又需要顯示進度)
session.sendAndRequest("/demo/download", SocketD.newEntity()).thenProgress((isSend, val, max)=>{
if(!isSend){
//獲取接收進度
}
}).thenReply(reply=>{
//異步獲取答復
}).thenError(err=>{
//如果有出錯?
});
//發(fā)送并訂閱
let entity = SocketD.newEntity().metaPut("videoId","1").meatPut("start","5").meatPut("size","5");
session.sendAndSubscribe("/demo/stream", entity).thenReply(reply=>{
//異步獲取答復(會多次回調)
})
視頻效果:文章來源地址http://www.zghlxwxcb.cn/news/detail-788654.html
- for H5
- https://www.bilibili.com/video/BV1ck4y197BV/
- for UniAPP
- https://www.bilibili.com/video/BV1T94y1T7sp/
代碼倉庫:
- https://gitee.com/noear/socketd
- https://github.com/noear/socketd
官網(wǎng):
- https://socketd.noear.org
到了這里,關于Socket.D v2.3 發(fā)布(打通前端與后端)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!