It may be desirable to send partial data held on disk rather than from memory. This can be easily achieved by using the provided wrapper object StreamSendWrapper:
//Create a filestream linked to the data on disk FileStream diskData = new FileStream("testfile.dat", FileMode.Open); //Wrap the filestream in a thread safe stream which enables // thread safe stream operations. ThreadSafeStream threadSafeStream = new ThreadSafeStream(diskData); //Wrap the thread safe stream in StreamSendWrapper which records the data to be sent //We intend to send the first 1024 bytes from testfile.dat StreamSendWrapper sendWrapper = new StreamSendWrapper(threadSafeStream, 0, 1024); //Send the data specified within sendWrapper NetworkComms.SendObject("testFileData", "192.168.0.1", 10000, sendWrapper);
The receiving client should handle the incoming data as byte[]:
//Add a global packet handler for packet of type "testFileData" which will receive byte[] NetworkComms.AppendGlobalIncomingPacketHandler<byte[]>("testFileData", (packetHeader, connection, incomingData) => { Console.WriteLine("Recieved {0} bytes.", incomingData.Length); });
To see a worked example which uses StreamSendWrapper to send large files please see our file transfer application tutorial. If you have any further questions regarding the usage of StreamSendWrapper please post on our forums.