Sockets
Sockets are low-level objects that are responsible for sending and receiving raw data over the network.
Mirage has a single transport (called Mirage.SocketLayer.Peer
) built into its core, which handles all the connection
states and reliability. Peer then uses the low-level sockets API to send and receive raw data over the network.
Check this section below to see how to implement your own socket.
Available sockets
The table below shows a list of available sockets and their features.
UDP (built-in) | Steam (Steamworks.NET, Facepunch) | Websocket | |
---|---|---|---|
CCU | 1000+ | ? | ? |
Protocol | UDP | UDP | TCP |
Unreliable | ✅ | ✅ | ❌ |
Mobile | ✅ | ❌ | ✅ |
WebGL | ❌ | ❌ | ✅ |
CPU | LOW | LOW | ? |
NAT Punch | ❌ | ✅ | ❌ |
Encryption | ❌ | ✅ | ✅ |
IPv6 | ✅ | ? | ? |
Managed | ✅ | ✅ | ✅ |
Native | ✅ | ❌ | ❌ |
Based on | NanoSockets (native), .NET (managed) | Steam Game Networking Sockets | SimpleWebTransport |
Changing a socket
To change a socket, follow the steps below:
- Install the desired socket. Instructions are available on each socket's repository.
- Add the socket's
SocketFactory
as a new component on the object where you have the other Mirage components. - Assign a reference to this component in the
Socket Factory
field ofNetworkServer
andNetworkClient
components. - Check if the socket has any required additional steps.
- Done. Mirage should now be using the newly added socket.
Implementing new socket
To create a new socket, you have to implement two classes - one that implements the Mirage.SocketLayer.ISocket
interface, which will represent the low-level socket and one that extends the Mirage.SocketLayer.SocketFactory
class, which will act as the MonoBehaviour component creating new instances of the low-level class.
You can check out our built-in UDP socket implementation as an inspiration: Mirage.Sockets.Udp.UdpSocket
and
Mirage.Sockets.Udp.UdpSocketFactory
.