Click here to Skip to main content
15,884,877 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am having the problem in receiving values from the server/client. In the AsyncSocket::Receive function.
I am using the TCHAR *pbuff=new TCHAR[4096];
while receiving in pBuff. I can get only the first 3 characters.
Help me
Posted
Updated 30-Dec-10 19:48pm
v2

Hi

Have a look on this[^] might be help
 
Share this answer
 
Comments
Gokulnath007 31-Dec-10 4:47am    
void CServerClass::OnReceive()
{
TCHAR *pBuff=new TCHAR[40];
int iBuffSize=41;
int Rcvd;
//CString lvstrRecev;
Rcvd = m_client.Receive(pBuff,iBuffSize);
if(Rcvd==SOCKET_ERROR)
{
}
else
{
pBuff[Rcvd]=NULL;
CString lvstrRecev(pBuff);
m_lrecv.AddString(lvstrRecev);
UpdateData(FALSE);

}
}
Thank you. for the above reply... pls note that.. In this code.. the char pointer stores only the first 3 values... pls help me..
how much you send ? :) Your question is not clear enough to understand the problem. please post more details.
 
Share this answer
 
Comments
Gokulnath007 31-Dec-10 4:45am    
void CServerClass::OnReceive()
{
TCHAR *pBuff=new TCHAR[40];
int iBuffSize=41;
int Rcvd;
//CString lvstrRecev;
Rcvd = m_client.Receive(pBuff,iBuffSize);
if(Rcvd==SOCKET_ERROR)
{
}
else
{
pBuff[Rcvd]=NULL;
CString lvstrRecev(pBuff);
m_lrecv.AddString(lvstrRecev);
UpdateData(FALSE);

}
}
In this, the pointer character stores only the first 3 values... rectify it please.... I think u can understand it clearly..
fjdiewornncalwe 3-Jan-11 21:32pm    
@Gokulnath007: Please stop demanding that others do your work for you. Ask clear, specific questions and you will get the help you need, but you will still have to take the initiative to make an effort.
Gokulnath007 3-Jan-11 23:39pm    
yeah, I am also trying for it. If i get the answer. i ll do post it in the answer.. sorry to say this...
I have solved the problem... the code is below:: thank you.. for your cooperation...
void CServerClass::OnReceive()
{
	WCHAR *pBuff=new WCHAR[100];
	int iBuffSize=99;
	int Rcvd;
	CAsyncSocket rr;

	
	Rcvd = m_client.Receive(pBuff,100);
	if(Rcvd==SOCKET_ERROR)
	{ 
	}
	else											
	{
		pBuff[Rcvd]=NULL;
		CString lvstrRecev(pBuff);
		int nLength;
		nLength = lvstrRecev.GetLength();
		CString strTemp;
		for(int i=0;i<nLength/2;i++)
		{
			strTemp += lvstrRecev.GetAt(i);
		}
		m_lrecv.AddString(strTemp);
		UpdateData(FALSE);

	}
}
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 31-Dec-10 17:12pm    
Hard-coded buffer size is a supportability problem. Having related numbers in in more than on place is simply unacceptable. I mean, if you change 100 to 100+n, you also need to change 99+n; why not writing an explicit constant "buffSize" and using "buffSize" and "buffsize+1", etc.?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900