Splitting data in an ArraySegment<byte> to different Bytes[]

28 Views Asked by At

I'm trying to make a C# program that allows 2 computers to send files between each other, the client is the sender, the server is the receiver. The problem now is that I'm using ArraySegment which uses a Byte[] variable which apparently supports only upto 2.147gb of data (max int value), and I have an idea of taking overloading data into another Byte[] variable. But I don't know how to do it, I also want to fix the issue of the program using said byte size for any file size (for example: a .txt file with a size of 24kb, in memory, the byte would be stored as 1,073,741,824kb or 1.073gb) I want the byte[] to be the same size as the size of the data or atlease close to it.

Here's my code for this, also if there are any mistakes in my code or some optimizations could be made, I would be happy to know.

Buffer = new byte[1_073_741_824];

var BFR = new ArraySegment<byte>(Buffer, 0, Buffer); //[2_147_483_647]

var ReceivedByteLength = await Handler.ReceiveAsync(BFR, SocketFlags.None);

var BFR2 = new ArraySegment<byte>(Buffer, 0, ReceivedByteLength);

Console.WriteLine("File Request received from client.");

I tried researching and researching but could not really find anything related to my problem.

0

There are 0 best solutions below