The recv function is not properly working for me.
I am trying to send an array of strings from one computer to the other.
In most cases from the 4 variables only 2 are sent!.
It feels like the buffer on recv is not properly flushing or some other annoying ****.
This is how I sent:
for (unsigned int i = 0; i < m_vsListName.size(); ++i)
{
iResult = SendMessageToSocket(m_ClientSocket, m_vsListName.at(i).GetBuffer());
if (iResult == SOCKET_ERROR)
{
printf("Could not Send list. sent: %d, still to send: %d\n", i, m_vsListName.size() - 1);
return iResult;
}
}
====================
int SendMessageToSocket(SOCKET &SocketToSentTo, const char* pMessage)
{
return iResult = send(SocketToSentTo, pMessage, (int) strlen(pMessage) + 1, 0);
}
The +1 is for the "\n".
=============================================
This is how I receive.
int Cclient_streamDlg::GetList()
{
int iResult;
int recvbuflen = 512;
char recvbuf[512];
int i = 0;
do
{
iResult = recv(m_ConnectSocket, recvbuf, recvbuflen, 0);
if (iResult > 0)
{
CString str;
str.Format(L"%d", i + 1);
m_lcList.InsertItem(i, str);
m_lcList.SetItemText(i, 1, CStringW(recvbuf));
++i;
}
else if (iResult == 0)
{
printf("Clossing connection\n");
}
else
{
printf("Connection error\n");
}
} while (iResult > 0);
m_lcList.UpdateData();
return iResult;
}
Any clue why only those 2 are sent????