获取ReadString和一个神奇的数字128? [英] CArchive ReadString and a magic number 128?

查看:73
本文介绍了获取ReadString和一个神奇的数字128?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重新编写一个通过另一台计算机上的套接字与另一个应用程序(B)通信的应用程序(A).应用程序B用MFC编写,包含CArchive类.

现在,我对B代码还不是很了解,但是我注意到的一件奇怪的事是,当消息从A发送到B时,最终将消息发送到CArchive :: ReadString方法.如果此消息是一个字符数组,其大小为128的倍数,则可以正常工作-为每组128个字符调用OnReceive方法,并将每组128个字符发送到CArchive :: ReadString,后者完成并返回happilly .但是,如果有剩余字符(即小于128的char数组)传递给ReadString,则ReadString会卡住,系统会挂起.

I am re-writing an application (A) that communicates with another application (B) via sockets on another machine. Application B is written in MFC and contains the CArchive class.

Now, I don''t understand a lot about the B code yet, but an odd thing I have noticed is that when a message gets sent from A to B, it eventually gets sent to the CArchive::ReadString method. If this message is an array of character with a size that is a multiple of 128 it works fine - the OnReceive method gets called for each group of 128 characters and each set of 128 chars is sent to CArchive::ReadString which completes and returns happilly. However, if there is a remainder ie an array of chars which is less that 128 is passed to ReadString, then ReadString gets stuck and the system hangs.

Is there anyone who can shed some light on this please?

推荐答案

在MSDN帮助中我找到了这个...

In the MSDN Help I found this...

In the version of the member function with the nMax parameter, the buffer will hold up to a limit of nMax - 1 characters. Reading is stopped by a carriage return-linefeed pair. Trailing newline characters are always removed. A null character (''\0'') is appended in either case.

CArchive::Read is also available for text-mode input, but it does not terminate on a carriage return-linefeed pair.



在您打开它的模式下,它可能正在等待回车换行对.这是Telnet的默认行为.在这种模式下,期望用户在处理命令之前按下返回键.



In the mode that you have it opened for, it may be waiting on a carriage return line feed pair. This is the default behavior for Telnet. In this mode, it''s expecting the user to hit the return key, before processing the command.


这篇关于获取ReadString和一个神奇的数字128?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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