This repository has been archived by the owner on Aug 15, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 305
Creating, sending and receiving binary messages
Erik Nilson edited this page Oct 2, 2018
·
4 revisions
To send a binary frame, first create a BMSByte with the ObjectMapper, giving it the data you want to send. You can also add data to the byte with Append. Append takes a byte[] so we first need to convert our input.
BMSByte bytes = ObjectMapper.BMSByte(1, "a string", 2.0f);
bytes.Append(BitConverter.GetBytes(5));
bytes.Append(Encoding.ASCII.GetBytes("add a string"));
Then create the Frame.Binary object and send it
int MY_GROUP_ID = MessageGroupIds.START_OF_GENERIC_IDS + 1;
ulong timestep = client.Time.Timestep;
bool isTcpClient = client is TCPClient;
bool isTcp = client is BaseTCP;
Binary bin = new Binary(timestep, isTcpClient, bytes, Receivers.Target, MY_GROUP_ID, isTcp);
client.Send(bin);
Upon receiving the data, it is possible to get the data like this:
server.binaryMessageReceived += (player, msg, sender) =>
{
if (msg.GroupId == MessageGroupIds.START_OF_GENERIC_IDS + 1)
{
int number = msg.StreamData.GetBasicType<int>();
string text = msg.StreamData.GetBasicType<string>();
float f = msg.StreamData.GetBasicType<float>();
}
};
}
Note: you can replace server with client and vice versa, both TCP/UDPServer and -Client have the binaryMessageReceived event.
Getting Started
Network Contract Wizard (NCW)
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
Master Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
-
Connection Cycle Events
-
Rewinding
-
Network Logging
-
Working with Multiple Sockets
-
Modify Master and Standalone servers
-
NAT Hole Punching
-
UDP LAN Discovery
-
Offline Mode
-
Ping Pong
-
Lobby System
-
Upgrading Forge Remastered to Develop branch or different version
-
Forge Networking Classic to Remastered Migration Guide
-
Script to easily use Forge Networking from sources
-
Run Two Unity Instances with Shared Assets for Easiest Dedicated Client Workflow