UDP Application on Vista: Fail on sendto function
-
Hello, I have UDP app that works fine, except on Windows Vista. The error is WSAEINVAL (10022) on sendto function, and the package did not send :-( Anyone know this problem? Thanks, Cris.
Tough to guess without knowing the code :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Hello, I have UDP app that works fine, except on Windows Vista. The error is WSAEINVAL (10022) on sendto function, and the package did not send :-( Anyone know this problem? Thanks, Cris.
Cris wrote:
The error is WSAEINVAL (10022) on sendto function...
WSAEINVAL
= "An unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled."
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Cris wrote:
The error is WSAEINVAL (10022) on sendto function...
WSAEINVAL
= "An unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled."
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
This is my code:
SOCKET m_maSocketOut; struct sockaddr_in m_SockAddrOut; unsigned long m_lInet; . . void init(CString strServer) { unsigned long lInet=0; memset(&m_SockAddrOut, 0, sizeof(m_SockAddrOut)); m_maSocketOut = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); m_SockAddrOut.sin_family = AF_INET; m_SockAddrOut.sin_port = htons(port); struct hostent FAR* hp = gethostbyname((char FAR *) (const char *) strServer); if (hp == NULL) { lInet = inet_addr((const char * ) strServer); if (lInet != INADDR_NONE) { validIP = TRUE; byAddress = TRUE; } } else validIP = TRUE; if (validIP) { if (byAddress) { m_SockAddrOut.sin_addr.s_addr = lInet; m_lInet = lInet; } else { m_SockAddrOut.sin_addr.s_addr = *((unsigned long far *) hp->h_addr); m_lInet = *((unsigned long far *) hp->h_addr); } if (m_maSocketOut != NULL) { bind(m_maSocketOut, (SOCKADDR*)& m_SockAddrOut, sizeof(m_SockAddrOut)); WSAAsyncSelect(m_maSocketOut, hWnd, WM_EXTERNA, FD_READ | FD_CLOSE); } } } void sendData(char szData[], int len) { int result = sendto(m_maSocketOut, (char FAR *) &szData, len, NULL, (PSOCKADDR) &m_SockAddrOut, sizeof(m_SockAddrOut)); m_SockAddrOut.sin_addr.s_addr = INADDR_ANY; if (result < 0) { int erroCode = WSAGetLastError(); //erroCode = 10022 in Windows Vista!! } }
Important: This error code is only on Windows Vista, but not all instalations . I don't know which the exat situation, but I observed in Business and Ultimate version. Any idea? -
This is my code:
SOCKET m_maSocketOut; struct sockaddr_in m_SockAddrOut; unsigned long m_lInet; . . void init(CString strServer) { unsigned long lInet=0; memset(&m_SockAddrOut, 0, sizeof(m_SockAddrOut)); m_maSocketOut = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); m_SockAddrOut.sin_family = AF_INET; m_SockAddrOut.sin_port = htons(port); struct hostent FAR* hp = gethostbyname((char FAR *) (const char *) strServer); if (hp == NULL) { lInet = inet_addr((const char * ) strServer); if (lInet != INADDR_NONE) { validIP = TRUE; byAddress = TRUE; } } else validIP = TRUE; if (validIP) { if (byAddress) { m_SockAddrOut.sin_addr.s_addr = lInet; m_lInet = lInet; } else { m_SockAddrOut.sin_addr.s_addr = *((unsigned long far *) hp->h_addr); m_lInet = *((unsigned long far *) hp->h_addr); } if (m_maSocketOut != NULL) { bind(m_maSocketOut, (SOCKADDR*)& m_SockAddrOut, sizeof(m_SockAddrOut)); WSAAsyncSelect(m_maSocketOut, hWnd, WM_EXTERNA, FD_READ | FD_CLOSE); } } } void sendData(char szData[], int len) { int result = sendto(m_maSocketOut, (char FAR *) &szData, len, NULL, (PSOCKADDR) &m_SockAddrOut, sizeof(m_SockAddrOut)); m_SockAddrOut.sin_addr.s_addr = INADDR_ANY; if (result < 0) { int erroCode = WSAGetLastError(); //erroCode = 10022 in Windows Vista!! } }
Important: This error code is only on Windows Vista, but not all instalations . I don't know which the exat situation, but I observed in Business and Ultimate version. Any idea?Could it be a UAC thing?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Could it be a UAC thing?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I have solved the problem... removing the bind() function execution. Acording with the MSDN documentation: "The bind function is used on an unconnected socket before subsequent calls to the connect or listen functions. It is used to bind to either connection-oriented (stream) or connectionless (datagram) sockets. When a socket is created with a call to the socket function, it exists in a namespace (address family), but it has no name assigned to it. Use the bind function to establish the local association of the socket by assigning a local name to an unnamed socket." I understood that the bind function is not necessary, because I only want to send datagrams with a SOCKET to server and receive the responses by the same SOCKET, and the WSAAsyncSelect function grants the data response to the app. This is correct? Thanks, Cris.