A substitute for [ServerRPC]
, NData provides an abstraction for Client -> Server data transfer, using ConCommands as a transport.
// on client
bytes[] payload = FileSystem.Data.ReadAllBytes( "kittens.jpg" ).ToArray();
NData.Client.SendToServer( "eventname", payload );
// on server
[Event( "ndata.received.eventname")]
static void OnReceived( IClient client, byte[] payload )
{
Log.Info( $"Received {payload.Length} bytes from {client.Name}" );
using ( Stream s = FileSystem.Data.OpenWrite( "out.jpg" ) )
s.Write( payload );
}
The payload will be compressed, split into 373 byte chunks, base64 encoded, and sent to the server using throttled ConCommands (33/s = 11kb/s). The server will reassemble the payload, decompress it, and then emit the event.
Just use [ClientRPC]
, its much faster and supports 1mb payloads.
- SandboxPlus - for uploading Duplicator dupe files to the server