This project aims to make the process of integrating multiplayer into your game just one click away. This project is completely free, covered by the MIT license, and imposes no restrictions on the server or client whatsoever.
The core of this server is the Web Socket protocol. It is implemented in C# using the .NET Sockets API. This API was recently adopted by Microsoft into the .NET core framework, meaning this will be supported, stable, and maintained for the forseeable future. It is based on the Transmission Control Protocol (TCP), which receives a lot of negative attention in the gaming community. However, we considered some critical improvements made when creating Web Sockets, and decided it was fit for the project. We aim to show the viability of C# and web sockets as a general purpose game server.
During the initial development, we are only offering a graphical version of the server application. The first release will also include a truly bare-bones console application with identical functionality.
- If you're going to host online, choose a TCP port to host on (we use 5050)
- Make sure the selected port is available to outside connections
Quick guide for Windows...
- Click start, and search for "Windows Defender Firewall"
- Click "Advanced settings"
- Click "Inbound rules"
- Click "New Rule..."
- Select "Port"
- Select "Specific local ports"
- Enter your chosen port (default is 5050)
- Select "Create Rule"
- Download this git repository as a .zip using the green code button.
- Extract it wherever you'd like your server program to be stored
- Run the 'gameserver.exe' from the extracted directory
- Configure your settings, using the newly-opened port
- Go back to the server program
- Click 'Apply and Start Server'
- First make sure you have the following requirements:
- Visual Studio (the Community version is free) or another C# IDE (such as IDEA)
- .NET 3.5 framework (for running WebSocketServer)
- Redis installed
- Once server files have been configured, simply open, modify, rebuild, and run the solution
Show/hide
This is where the compiled program will be. Run this to start the server.
Show/hide
This is also made by VS but you shouldn't need to touch it. No need to link it to Unity, as it's separate from the client entirely.
Show/hide
The main method of server is here. It just initializes network packages, sets up the server, and waits for input so the console doesn't close.
Show/hide
Find constants like the server IP, port, and maximum connection queue size, here.Show/hide
The types of network packets we can send from client to server and server to client are defined here. Each is in its own enum. The integer associated each determines the handler function that is executed in ServerPackHandler.cs.
Show/hide
This file has our InitializeNetworkPackages method, which fills our dictionary assiociating our packets with their handler functions. It defines each packet handler (i.e. what to do with each type of packet it gets from the client).
Show/hide
This is out network packet buffer.
Answers to the whole universe.
Magic.