During my erasmus I wanted to learn something new and exciting! So I chose for learning about network programming. An excited but incredibly deep topic.
This networked boid simulation is to show of the skills I’ve learned during that semester. The simulation itself is very unoptimized and brute. It does not do anything smart like partioning the space or distributing it over multiple cores. The goal was to learn about sockets programming and implement this in a realtime application.
The video below quickly demonstrates how this works:
The source can be found on github.
- Build the project
- Execute the rel_servers script to start up the servers
- Execute the rel_connect script to connect to a server
Left clicking when connected to a server will spawn a boid on the field. The servers show a visual display for debugging purposes.
Seeing as this was my very first time working with sockets and networking programming I hit a lot of roadblocks and had a lot of problems that got refactored out. Below some key characteristics of the application:
- SFML framework
- UDP sockets
Server-to-Server comms: Peer2Peer
- All simulations happen on the servers. Clients are merely an display and input to influence the simulation world.
- Client-to-Server comms: Dedicated, the client only receives data from 1 server
For this project I’ve chosen for a multi server architecture that commenly gets used in bigger mmorpgs.
The biggest pro of using a multi server architecture is that we can distribute our simulations to different servers and have to client only receive the data it’s interested in. The user also does not have to worry massively about their data usage as they won’t be sending duplicated data, in contrary to P2P networking. We can also avoid NAT problems since the client needs to connect to our server first, giving us a path to them.
Below there is a list of things that I want to keep in mind in later projects.
- Better structure for handling network packet translations and processing. This would make it easier for me to keep a better overview of sorting the packets, omitting redundant information.
- Multithreaded model for simulation instead of single threaded. The network processing can then also happen in it’s own thread similar to Unreal Engine does HTTP threads etc.
- The way I keep track of what boid belongs to what client is with ID’s that are stored in maps. This is very error prone and I would like to find a better way for solving this, maybe linking the IP address for each boid with already make it easier to determine who is the owner of that boid.