如何从MFC中的特定字节开始读取文件中的文本 [英] How do I start reading text in file from specific byte in MFC

查看:254
本文介绍了如何从MFC中的特定字节开始读取文件中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MFC中设计了服务器和客户端,在连接完成后进行一次文件传输。例如,我从服务器向客户端发送200个字符的文件,但客户端接收函数中的缓冲区大小仅为100(char buf [100])。如果是这种情况,我会向服务器发送命令以发送剩余数据。如何从第101个角色开始发送?



我尝试过:



服务器:

 CFile Sourcefile; 
Sourcefile.Open(strFilePath,CFile :: modeRead);
ULONGLONG dwLength = Sourcefile.GetLength();
command_header.Databuffer = new char [(int)dwLength + 1];
UINT nActual = Sourcefile.Read(command_header.Databuffer,dwLength);
command_header.Databuffer [nActual] = 0;
nRet = SockConnection.Send(command_header.Databuffer,nActual);





客户:

 nRet = SockConnection.Receive(iBuf,100); 
while(iBuf [nRet]!='\ 0'){
AfxMessageBox(L发送剩余数据);
hCommand_header.command = FILE_SIZE;
nRet = SockConnection.Send((char *)& hCommand_header.command,sizeof(hCommand_header.command));

解决方案

< blockquote>服务器在一次传输中发送所有数据,因此没有更多的工作要做。客户端需要通过在接收磁盘时将每个块写入磁盘来构建文件。唯一的问题是客户无法知道何时收到所有数据。您需要在两个系统之间创建一个消息协议,以便它们可以传递有关正在传输的数据量的信息。


I have designed server and client in MFC which does file transfer once after connection is made. For Example, I'm sending file with 200 characters from server to client but the buffer size in client's receive function is only 100(char buf[100]). if that is the case, I'm sending command to server to send remaining data. How to start sending from 101th character?

What I have tried:

Server :

CFile Sourcefile;
Sourcefile.Open(strFilePath, CFile::modeRead);
ULONGLONG dwLength = Sourcefile.GetLength();
command_header.Databuffer = new char[(int)dwLength + 1];
UINT nActual = Sourcefile.Read(command_header.Databuffer,dwLength);
command_header.Databuffer[nActual] = 0;
nRet = SockConnection.Send(command_header.Databuffer, nActual);



Client :

nRet = SockConnection.Receive(iBuf, 100);
while(iBuf[nRet] != '\0') {
AfxMessageBox(L"Send remaining data");
hCommand_header.command = FILE_SIZE;
nRet = SockConnection.Send((char*)&hCommand_header.command, sizeof(hCommand_header.command));

解决方案

The server is sending all the data in a single transmission, so there is no more work for it to do. The client needs to build the file by writing each block to disk as it receives it. The only problem for you is that the client has no way of knowing when all the data has been received. You need to create a message protocol between the two systems so they can pass information about the amount of data that is being transmitted.


这篇关于如何从MFC中的特定字节开始读取文件中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆