Originally Posted by
eXistenZ
to be honest i have no idea what it is lol i just used CAsyncSocket wsClient; and wsClient.Create();
i guess it works at that way anyway i get all the data but i get extra characters check this out:
Code:
void CChateXDlg::OnReceive(int nErrorCode)
{
if(nErrorCode==0)
{
int rcv;
char dta[100];
CString txt;
rcv=wsClient.Receive(dta,100,0);
if(rcv==0)
{
Data+=dta;
}
else
{
Data=dta;
m_re1.GetWindowText(txt);
m_re1.SetWindowText(txt+CString("\n")+Data);
}
}
}
i used to get extra weird chars before too.. maybe i did something wrong in the code ?
btw Data is declared outside this OnReceive function in the dialog.cpp file so it wont end
Ok so it looks like you are using async sockets... since well you are using the CasyncSocket class here. If you noticed "Data" after the first iteration is exactly 100 characters long. Its whatever you received + the rest of the "dta" buffer. You must NULL terminate the buffer when you receive so you can correctly add it to "Data". You know the number of characters received, since "rcv" has that information.
So after this line...
Code:
rcv=wsClient.Receive(dta,100,0);
add in this...
then you shouldn't be getting those funky characters...
Sometimes it helps if you explain the whole problem first, explain what you are using, maybe your justification as to why and add in as much information as possible...
Incidentally... this line is wrong...
Code:
if(rcv==0)
{
Data+=dta;
}
if rcv is 0 then check the WSAGetLastError() function you can do this by doing something like this...
Code:
if( rcv == 0 )
{
int error = WSAGetLastError( );
//then find the error and print in out
TRACE1("The error I got is %d", error);
//or
CString errormsg;
errormsg.format("I found the error %d", error);
AfxMessageBox(errormsg);
}