Skip to content

Send Binary Frame

Daniel McGuinness edited this page Sep 30, 2018 · 1 revision

The Binary frame (BeardedManStudios.Forge.Networking.Frame.Binary) is a child of the FrameStream object which is how all messages are sent in Forge (even our internal code). To use this you need to serialize your data to a byte[] or pack it into a BMSByte object (wrapper around byte[] for caching).

First you need to create your data

byte[] data = { /* Your data */ };

Next you need to create the frame, since you want to send it to a specific player you will need to make the receivers be Target

const MY_GROUP_ID = MessageGroupIds .START_OF_GENERIC_IDS + 1; // Just a random message group id that is not being used anywhere else
ulong timestep = NetworkManager.Instance.Networker.Time.Timestep;
bool isTcpClient = NetworkManager.Instance.Networker is TCPClient;
bool isTcp = NetworkManager.Instance.Networker is BaseTCP;
Binary bin = new Binary(timestep, isTcpClient, data, Receivers.Target, MY_GROUP_ID, isTcp);

Now that you have your binary frame named "bin", you can send it across the network. This is assuming that you are sending this frame from the server

if (networker is UDPServer)
    bool isReliable = true;
    ((UDPServer)networker).Send(targetNetworkingPlayer, bin, isReliable);
    ((TCPServer)networker).Send(targetNetworkingPlayer, bin);

To read this message you need to listen to the NetWorker::binaryMessageReceived event on the client. You can filter by the group id you've specified

NetworkManager.Instance.Networker.binaryMessageReceived += ReadBinary;

// ...

private void ReadBinary(NetworkingPlayer player, Binary frame, NetWorker sender)
    if (frame.GroupId != MY_GROUP_ID)

    // TODO:  Your code here


Getting Started
Network Contract Wizard (NCW)
Network Object
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
Master Server
Web Server
Netcoding Design Patterns
Clone this wiki locally
You can’t perform that action at this time.