We help IT Professionals succeed at work.
Get Started

Winsock 2.2 recv not working

Last Modified: 2013-12-03
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;

            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));
            else if (iResult == 0)
                  printf("Clossing connection\n");
                  printf("Connection error\n");

      } while (iResult > 0);


      return iResult;

Any clue why only those 2 are sent????
Watch Question
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE