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);}}
评论