Protocol Files | How Send Big Files

When you want to send big files to Server or Client, for example a File of some Gigabytes, you can experience some memory problems trying to load the full file. The Protocol Files allows you to send the files in smaller packets that when received by other peer are reassembled in a single file. Just use the Size parameter of SendFile method to set the Size in Bytes of every single packet.

 


// ... Create Server
oServer := TsgcWebSocketServer.Create(nil);
oServer_Files := TsgcWSPServer_Files.Create(nil);
oServer_Files.Server := oServer;
oServer.Host := '127.0.0.1';
oServer.Port := 8080;

// ... Create Client oClient := TsgcWebSocketClient.Create(nil); oClient.URL := 'ws://127.0.0.1:8080';
// ... Create Protocol oClient_Files := TsgcWSPClient_Files.Create(nil); oClient_Files.Client := oClient;
// ... Start Server oServer.Active := True;
// ... Connect client and Send File in packets of 100000 bytes if oClient.Connect() then   oClient_Files.SendFile('c:\Documents\yourfile.txt', 100000, qosLevel0, '');