高性能TcpServer(C#) - 4.文件通道(处理:文件分包,支持断点续传)
高性能TcpServer(C#) - 2.创建高性能Socket服务器SocketAsyncEventArgs的实现(IOCP)
高性能TcpServer(C#) - 3.命令通道(处理:掉包,粘包,垃圾包)
高性能TcpServer(C#) - 4.文件通道(处理:文件分包,支持断点续传)
应用场景
升级程序
流程:终端->查询服务器版本比较->升级程序(获取包数,获取各包数据)->数据拼装生成文件->最后更新服务器上该设备的版本信息
分包代码段:
static Dictionary<int, string> ReadFile(string path)
{
Dictionary<int, string> dicFileData = new Dictionary<int, string>();
FileStream fs = new FileStream(path, FileMode.Open);
BinaryReader binReader = new BinaryReader(fs);
int bagindex = 1;
int dataindex = 0;
byte[] bBuffer = new byte[fs.Length];
int bagsize = 235;// 一包数据大小
byte[] temp = new byte[bagsize];
binReader.Read(bBuffer, 0, (int)fs.Length);
for (int i = 0; i < bBuffer.Length; i++)
{
if ((bagsize - 1) == dataindex || (bBuffer.Length - 1) == i)
{
if ((bBuffer.Length - 1) == i) temp[dataindex++] = bBuffer[i];
string data = CCommonFunc.ToHexString(temp, dataindex, false);
dicFileData.Add(bagindex, data);
bagindex++;
dataindex = 0;
temp = new byte[bagsize];
}
temp[dataindex++] = bBuffer[i];
}
binReader.Close();
fs.Close();
return dicFileData;
}
测试:
最新文章
- Dynamics CRM 之ADFS 使用 WID 的联合服务器场
- 利用Python进行数据分析(3) 使用IPython提高开发效率
- ";_OBJC_CLASS_$_CMMotionManager";, referenced from:
- JAVA中取余(%)规则和介绍
- 【wikioi】1553 互斥的数(hash+set)
- DataBase: MySQL在.NET中的应用
- 属性的定义以及@synthesize的使用
- Iframe的应用以及父窗口和子窗口的相互访问
- 改变navigationbar 标题颜色
- Ubuntu 怎么在右键添加打开终端
- python代码风格规范
- 【HTML】模板
- TP框架设置的LOG_LEVEL不起作用
- 转:rabbitMQ 安装与管理
- Maven插件一览
- Entity Framework Core系列之实战(ASP.NET Core MVC应用程序)
- apache2.4 文件浏览服务器页面配置
- nginx-fastcgi 第九章
- C++中的getline()
- yocto-sumo源码解析(二): oe-buildenv-internal