本文介绍了使用套接字的MFC应用程序似乎很奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是服务器应用程序的消息接收功能:

Here is the message receiving function of the Server Application:

void CServerDlg::ReceiveData(CSocket & socket)
{
	char bufferdata[BUFFERSIZE];
	int len = socket.Receive(bufferdata,BUFFERSIZE);
	if (len != -1)
	{
		bufferdata[len] = '\0';
		POSITION pos = m_socketlist.GetHeadPosition();
		std::cout << len ;
		std::cout << "got";
		std::cout << bufferdata << '\n';
		while (pos != NULL)
		{
			CClientSocket* socket = (CClientSocket*)m_socketlist.GetNext(pos);
			if (socket != NULL) {
				socket->Send(bufferdata, len);
			}
		}
	}

}



我只想打印从中获取的文本客户端应用程序在控制台窗口中,但它不显示文本,只是一个正确的LEN号码和一个得到。

但令我困惑的是,客户端应用程序接收正确的文字!!多么奇怪!!!!



我的尝试:



我试图把

[std :: cout<< len;

std :: cout<< 得到;

std :: cout<< bufferdata<< '\ n';]

在while {...}下,以避免它没有完全收到文本的情况,但问题仍然存在。请告诉我该怎么办呢?


I just want to print the text it gets from the Client Application in the console window, but it dose not show the text, but just a right number of the LEN, and a "got".
But what confuses me is, however, the Client Application receive the text rightly!!How strange it is!!!!

What I have tried:

I've tried to put
[std::cout << len ;
std::cout << "got";
std::cout << bufferdata << '\n';]
under the while{...}, to avoid the case that it didn't receive the text completely, but the problem still exist. Please tell me how can I do for this?

推荐答案


这篇关于使用套接字的MFC应用程序似乎很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:04
查看更多