Laminar 多人 fps 游戏 UDP 协议开源项目

我要开发同款
匿名用户2021年10月26日
76阅读
开发技术Rust
所属分类网络工具包、程序开发
授权协议Apache 2.0

作品详情

Laminar是一种应用级传输协议,为快节奏的fps游戏提供基于UDP的可配置可靠性和排序保证,且提供轻量级的界面。

它的灵感来自GafferonGames,功能类似RakNet,SteamSocket,netcode.io。通过Rust写的低级UDP协议来支持多人游戏联网功能(尤其是FPS游戏),Laminar一般用于 Amethyst 游戏引擎,不过没它也能用。

特性:碎片化 不可靠的数据包 不可靠的排序数据包 可靠的无序数据包 可靠有序的数据包 可靠的排序数据包 Rtt估算 协议版本监控 基本连接管理 Heartbeat 基础的DoS缓冲 高时序控制 协议版本控制 集成和单元测试良好 可以被多个线程使用(Sender,Receiver)协议握手协议高级连接管理密码密匙体系(Cryptography)拥塞控制用例:UDPAPI -发送数据uselaminar::{Socket,Packet};//Createsthesocketletmutsocket=Socket::bind("127.0.0.1:12345")?;letpacket_sender=socket.get_packet_sender();//Startsthesocket,whichwillstartapollmechanismtoreceiveandsendmessages.let_thread=thread::spawn(move||socket.start_polling());//Bytestosentletbytes=vec![...];//Createspacketswithdifferentreliabilitiesletunreliable=Packet::unreliable(destination,bytes);letreliable=Packet::reliable_unordered(destination,bytes);//Specifiesonwhichstreamandhowtoorderourpackets,checkoutourbookanddocumentationformoreinformationletunreliable=Packet::unreliable_sequenced(destination,bytes,Some(1));letreliable_sequenced=Packet::reliable_sequenced(destination,bytes,Some(2));letreliable_ordered=Packet::reliable_ordered(destination,bytes,Some(3));//Sendsthecreatedpacketspacket_sender.send(unreliable).unwrap();packet_sender.send(reliable).unwrap();packet_sender.send(unreliable_sequenced).unwrap();packet_sender.send(reliable_sequenced).unwrap();packet_sender.send(reliable_ordered).unwrap();UDPAPI -接收数据uselaminar::{SocketEvent,Socket};//Createsthesocketletmutsocket=Socket::bind("127.0.0.1:12346")?;letevent_receiver=socket.get_event_receiver();//Startsthesocket,whichwillstartapollmechanismtoreceiveandsendmessages.let_thread=thread::spawn(move||socket.start_polling());//Waitsuntilasocketeventoccursletresult=event_receiver.recv();matchresult{Ok(socket_event)=>{matchsocket_event{SocketEvent::Packet(packet)=>{letendpoint:SocketAddr=packet.addr();letreceived_data:&[u8]=packet.payload();}SocketEvent::Connect(connect_event)=>{/*aclientconnected*/}SocketEvent::Timeout(timeout_event)=>{/*aclienttimedout*/}SocketEvent::Disconnect(disconnect_event)=>{/*aclientdisconnected*/}}}Err(e)=>{println!("Somethingwentwrongwhenreceiving,error:{:?}",e);}}
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论