Samples

Overview of the samples and test code. All the following samples are located under Samples\Code Samples Autopatcher Intermediate The autopatcher sample demonstrates the user of the autopatcher system. To run it, start two instances of the program. One instance will act as the sender, or the server. The other system will act as the receiver, or client. The server will pick two files to make downloadable while the client will pick a directory to check against. The client will then connect to the server, see if it has the files the server specified in the download directory, and if not or if they are changed will download them. See autopatcher.html for more details. BitStream Beginner The bitstream sample doesn't have much functionality but is instead intended to provide a clear sample of how to write and read bitstreams. It is all contained in one program and uses RPC to transmit the data. It writes a string and some numbers and shows how to read branching data. Chat Example Beginner The chat example directory contains two projects: A simple chat server and a simple chat client. Unlike a real game, it encodes strings directly into the data stream and reads them out directly. Normally you would use a packet ID. It use static data to transmit the name and message of the day. To test, run two or more instances of the program. Client File Verification Intermediate This sample will read all the files in the Debug directory, generate a 20 byte SHA-1 code for them, and send that over the network. If the code generated by the client and server match then the files are good. This shows a simple way to test the integrity of files on the client - although you will have to take other steps to prevent them from being modified in memory or changed after this test. Compression Intermediate This sample shows how to use the global compression scheme in RakNet. You have to start two or more instances of the program, passing nothing when queried for the frequency tables. Then chat for a while to 'train' the data. After quitting you will be prompted to save the frequency tables. The server should then send its frequency table to the clients, and one of the clients send its frequency table to the server. Fpr better accuracy you can sum up the frequencies from all the clients and send that. Then start the program over again and enter the files you just generated when prompted. If everything works, you can chat again. When you quit you will be given statistics on how much bandwidth you saved by sending compressed data. DistributedNetworkObject Intermediate The DNO system is fairly easy to use and follow if you look at DistributedNetworkObject.h and distributed network objects. This sample explains the same thing in code, with a lot of comments at each step of the process. You should run multiple instances of the program for testing. Dropped Connection Test Intermediate This test randomly starts and stops connections for n clients, where n can be changed from a define at the top of the file. Since all clients are in the same exe on the same computer the n threads created may slow things down. Encryption Advanced This is a tutorial on how to load, save, and use RSA keys with secure connections. The process is difficult to explain in a manual but easy to follow in code. Helpful to have some familiarity with RSA encryption. Flow Control Test Intermediate RakNet automatically handles flow control, which is evident from this test. This test only really has meaning when run over the internet, where there is limited bandwidth. You can also try running in debug with _INTERNET_SIMULATOR defined. LANServerDiscovery Intermediate Sends an offline ping to everyone at IP "255.255.255.255". All active servers on a LAN should respond with a pong. LoopbackPerformanceTest Advanced The loopback performance test is good for discovering implementation flaws and measuring implementation efficiency. It is fairly complex with a large number of parameters but has defaults for everything - just hit enter. You will need to start 3 instances of the program and enter 1, then 2, then 3 when prompted. You can hit enter for all other parameters if you wish. Detailed statistics are shown during runtime and at the end of the test. MasterServer Intermediate Like the chat example, this is two projects: a master server and a master client. It's very similar to stand-alone master servers in that you can add and remove rules, query for rules, and other things. The two user files in those projects are MasterServer.h and MasterClient.h. The test files are MasterServerMain.cpp and MasterClientMain.cpp. See the header files for a full list of functions and documentation of each function. See masterserver.html for more details. Ping Beginner Starts a server, then a client, then does an unconnected ping between the two. RakVoice Intermediate This project is a test of the RakVoice system. main.cpp uses portaudio to read and output sounds. This uses peer to peer connections between all chatting systems. See rakvoice.html for more details. Reliable ordered test Beginner Continually sends packets using reliable ordered from a sender to a receiver. The receiver checks the packet data to make sure the packets arrived in order. Remote Procedure Calls Beginner Shows how to send a message to the server using RPC, and then using RPC to send that message back to the client. Very simple - just look at the code. ServerEnumeration and StaticClient Data Intermediate A client connects to a server and static data is shared between them. This sample covers all functionality associated with this and shows the more complex cases where you want to update data on the other system or only change data locally. Timestamping Beginner In this sample, a sender writes the timestamp identifier and a timestamp into a byte stream and sends it to a recipient. It demonstrates how RakNet will automatically modify the timestamp so that it is system relative.

See Also

Index