Breep开源项目

我要开发同款
匿名用户2021年11月30日
30阅读
开发技术C/C++
所属分类程序开发、网络工具包
授权协议EUPL-1.1 License

作品详情

BreepWhatisBreep?

Breepisac++bridgedpeertopeerlibrary.Whatdoesthatmean?Itmeansthateventhoughthenetworkisconstructedasapeertopeerone,theremaybenodirectconnectionsbetweentwodudes,sayAandB,iftheseconnectionsareimpossible(duetopoorlyconfiguredports,forexample).Inthatcase,BreepwillattempttouseanotherpeerCasabridgebetweenAandB.Breepisalsoahigh-levellibrary.Youdon'thavetocareonwhenpeersconnect,disconnect,senddata,andonhowtosendyourclasses.Yousimplyregisterlistenersthatgetnotifiedwhenpeerscomeandgo,whentheysendyoustuff.Youmayevenuseserializationandsendyourownobjectdirectlythroughthenetwork.Samegoesforyourlisteners:youdon'tsay'Iwanttolistenforpilesofbytes',butinsteadyousay'Iwanttolistenforfancy::MyClass'.

HowdoIuseBreep::network?

Thebestwaytonowitistoreadthetutorials.Alternatively,youmayreadsomeexamplesandtheonlinedoc.Butasalittlepreview,hereisa'HelloWorld!'-typeexample:

Hereishowtocreateanetwork,startlisteningonport1234,andsend"Hello!"toanybudythatconnects:

BREEP_DECLARE_TYPE(std::string)voidco_listener(breep::tcp::network&network,constbreep::tcp::peer&source){network.send_object_to(source,std::string("Hello!"));}intmain(){breep::tcp::networknetwork(1234);network.add_connection_listener(&co_listener);network.sync_awake();return0;}

TheBREEP_DECLARE_TYPEinvolvedhereisusedtotelltobreep::networkthatwewilllisten/sendsomestd::strings.Ifyouforgettodoit,youwillgetacompile-timeerror.

Thereishowtodotheopposite:thenetworkstartslisteningonport1233,triestoconnectatlocalhost:1234,printsthefirstmessageitsees,thendisconnect:

BREEP_DECLARE_TYPE(std::string)voiddata_listener(breep::tcp::netdata_wrapper<std::string>&dw){std::cout<<dw.data<<std::endl;dw.network.disconnect();}intmain(){breep::tcp::networknetwork(1233);network.add_data_listener<std::string>(&data_listener);if(!network.connect(boost::asio::ip::address_v4::loopback(),1234)){std::cout<<"Failedtoconnect.\n";return1;}network.join();return0;}

Pleasedon'tgetconfused:thereisnoUDPinthislib(yet).

WhyshouldIuseBreep::network?It'sawesome!It'shighlevel:youcandirectlysendandreceiveobjects.Theoverheadforthisislow:ifyousetupwellyourserialization,youonlyhaveafixed64bitsextraoverhead(comparedtosendingrawbytestothep2pnetwork—incomparison,TCPhas320bitsofoverheadonlyforitsheader)It'seasytogetin:justreadtheexamples,you'llsee!WhyshouldINOTuseBreep::network?Ithasnotbeentestedasmuchasitshouldhavebeen.It'sprobablybrokenforBigEndianarchitecture(Ihavenowaytotestthis,sorry;awarningshouldbedisplayedonsucharchitectures.)It'svery,veryslowtocompilewith.RequirementsResourceRequirementCompilerC++14compliantoraboveBoostBoost1.55oraboveRoadMapMilestoneFeatureStatus0.1Peertopeernetworkmanagementcomplete0.1Instantiatedobjectsdeliverycomplete1.0Improvedserializationcomplete1.0Multipleobjectsdeliveryinonegocompletex.xClientservernetworkmanagementonhold

TheprojectiscurrentlyontestingstagebeforethereleaseofBreep1.0.0

License

ThisworkisundertheEuropeanUnionPublicLicensev1.1.

YoumaygetacopyofthislicenseinyourlanguagefromtheEuropeanCommissionhere.

Extractofarticle13:

AlllinguisticversionsofthisLicence,approvedbytheEuropeanCommission,haveidenticalvalue.Partiescantakeadvantageofthelinguisticversionoftheirchoice.Author

LucasLazare,anITstudentfrustratedfromnotbeingabletoproperlyusejava'sbrokennetworklibrary,andinspiredbyKryoNet

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论