Do I have to bind an UDP socket in my client program, to receive data? (I always get WASEINVAL)...

Posted by Incubbus on Stack Overflow See other posts from Stack Overflow or by Incubbus
Published on 2010-06-16T20:44:28Z Indexed on 2010/06/17 1:02 UTC
Read the original article Hit count: 277

Filed under:
|
|
|

Hey There,

I have the following problem:

I am starting WSA, then I am creating a UDP socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP) and try to recvfrom on this socket, but it always returns -1 and I get WSAEINVAL (10022)... I don´t know why?...

When I bind the port, that does not happen...

But it is very lame to bind the clients socket... (As far as I remember, i never had this problem before:/ )...

Anyone knows why this happens?...

(I am sending data to my server, which anwsers[ or at least, tries to^^])...

Inc::STATS CConnection::_RecvData(sockaddr* addr, std::string &strData)
{
    int ret, len, fromlen;      //return code / length of the data / sizeof(sockaddr)
    char *buffer;       //will hold the data
    char c;

    //recv length of the message
    fromlen = sizeof(sockaddr);
    ret = recvfrom(m_InSock, &c, 1, 0, addr, &fromlen);
    if(ret != 1)
    {
#ifdef __MYDEBUG__
        std::stringstream ss;
        ss << WSAGetLastError();
        MessageBox(NULL, ss.str().c_str(), "", MB_ICONERROR | MB_OK);
#endif
        return Inc::ERECV;
    }...

© Stack Overflow or respective owner

Related posts about c++

Related posts about error