110,567
社区成员
发帖
与我相关
我的任务
分享
byte[] data
int totalLen = data.Length;
byte[] fileblock = new byte[4096];
int temp = totalLen / 4096;
for (int i = 0; i < temp; i++)
{
fileblock = new byte[4096];
Array.Copy(data, i, fileblock, 0, data.Length - 4096);
}
var result = tm.Aggregate(new List<List<byte>>(), (container, x) =>
{
if (container.Count == 0 || x == 94)
container.Add(new List<byte>());
else
container.Last().Add(x);
return container;
})
.Select(lst => lst.ToArray());
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
List<byte[]> splitteddata = SplitArray<byte>(data, 4);
foreach (var item in splitteddata)
{
Console.WriteLine(string.Join(", ", item.Select(x => x.ToString())));
}
byte[] d = JoinArray<byte>(splitteddata);
Console.WriteLine(string.Join(", ", d.Select(x => x.ToString())));
}
static List<T[]> SplitArray<T>(T[] data, int size)
{
List<T[]> list = new List<T[]>();
for (int i = 0; i < data.Length / size; i++)
{
T[] r = new T[size];
Array.Copy(data, i * size, r, 0, size);
list.Add(r);
}
if (data.Length % size != 0)
{
T[] r = new T[data.Length % size];
Array.Copy(data, data.Length - data.Length % size, r, 0, data.Length % size);
list.Add(r);
}
return list;
}
static T[] JoinArray<T>(List<T[]> arraies)
{
List<T> list = new List<T>();
foreach (T[] item in arraies)
{
for (int i = 0; i < item.Length; i++) list.Add(item[i]);
}
T[] r = new T[list.Count];
int n = 0;
foreach (T x in list)
{
r[n++] = x;
}
return r;
}
}
}
1, 2, 3, 4
5, 6, 7, 8
9, 10, 11, 12
13
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
Press any key to continue . . . public void Send ( Socket handler, byte[] data )
{
if (handler != null && handler.Connected)
{
try
{
handler.Send(data);
}
catch
{
}
}
}
这个data数据太大,在客户端接收的时候很慢哦,导致界面上显示也很慢。
由于data太大导致从服务器发送数据到客户端很慢。不知道大家有没有解决的方法哦。