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.xClientservernetworkmanagementonholdTheprojectiscurrentlyontestingstagebeforethereleaseofBreep1.0.0
LicenseThisworkisundertheEuropeanUnionPublicLicensev1.1.
YoumaygetacopyofthislicenseinyourlanguagefromtheEuropeanCommissionhere.
Extractofarticle13:
AlllinguisticversionsofthisLicence,approvedbytheEuropeanCommission,haveidenticalvalue.Partiescantakeadvantageofthelinguisticversionoftheirchoice.AuthorLucasLazare,anITstudentfrustratedfromnotbeingabletoproperlyusejava'sbrokennetworklibrary,andinspiredbyKryoNet
评论