CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2005
    Posts
    4

    problem while using WSARecvFrom()

    Hi!
    I'm new to winsock.
    I want two computer to communicata with UDP .
    But wen I run the receiver program ,there will be always a error.
    the errorcode is 10014 (invalid address)
    the receiver can receive the event FD_READ
    but when i use WSARecvFrom ,nothing can be read .
    Even more the receiver will receive the event FD_READ again and again ,
    Can you tell me why?

    the code :

    sender:

    m_addr.sin_addr.s_addr=inet_addr(m_faraddr);
    m_addr.sin_family=AF_INET;
    m_addr.sin_port=htons(20001);

    m_localaddr.sin_addr.s_addr=INADDR_ANY;
    m_localaddr.sin_port=htons(10001);
    m_localaddr.sin_family=AF_INET;

    WSABUF wsaBuf;
    wsaBuf.len=strMsg.GetLength();
    wsaBuf.buf=strMsg.GetBuffer(wsaBuf.len);
    int i=0;
    iRetCode=WSASendTo(m_socket,&wsaBuf,1,(DWORD*)&i,0,(SOCKADDR*)&m_addr,sizeof(SOCKADDR),NULL,NULL);



    receiver:


    m_faraddr.sin_addr.s_addr=inet_addr(m_addr);
    m_faraddr.sin_family=AF_INET;
    m_faraddr.sin_port=htons(10001);
    m_localaddr.sin_addr.s_addr=INADDR_ANY;
    m_localaddr.sin_port=htons(20001);
    m_localaddr.sin_family=AF_INET;

    m_socket=WSASocket(AF_INET,SOCK_DGRAM,0,NULL,0,WSA_FLAG_MULTIPOINT_C_LEAF|WSA_FLAG_MULTIPOINT_D_LEAF);
    .........................
    char buffer[0x1000];
    int iRet=0;
    DWORD ret=0;
    int iLen=sizeof(m_addr);
    int iFlag=0;
    WSABUF wsaRecvBuf;
    wsaRecvBuf.len=0x1000;
    wsaRecvBuf.buf=buffer


    iRet=WSARecvFrom(m_socket,&wsaRecvBuf,1 ,&ret,0,(SOCKADDR*)&m_faraddr,&iLen,NULL,NULL);
    /////here ret is always 0 and errorcode is 10014

    please help me!!!!

  2. #2
    Join Date
    Mar 2005
    Posts
    6

    Re: problem while using WSARecvFrom()

    Hello,
    5th param of WSARecvFrom isn't a DWORD but a DWORD*.

    try this:

    DWORD flags = 0;
    iRet=WSARecvFrom(m_socket,&wsaRecvBuf,1 ,&ret,&flags,(SOCKADDR*)&m_faraddr,&iLen,NULL,NULL);

  3. #3
    Join Date
    Mar 2005
    Posts
    4

    Re: problem while using WSARecvFrom()

    thanks for you reply!

    but i've try it in my program . the error code is still 10014. no letters could be receive. this error has troubled me for several days .and i still can't resovle it.

    the error 10014 means invalid address. is there something wrong with my address? or my receive buffer is not big enough?

  4. #4
    Join Date
    Mar 2001
    Posts
    2,529

    Re: problem while using WSARecvFrom()

    Use recvfrom and sendto instead.

    ahoodin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured