The whole error is:
Error 1 error C2065: 'socklen_t' : undeclared identifier c:\users\richard\documents\visual studio 2010\projects\server\server\server.cpp 41 1 Server
This is the problematic line:
int iRcvdBytes=recvfrom(iSockFd, buff, 1024000, 0, (struct sockaddr*)&cliAddr, (socklen_t*)&cliAddrLen);
I have these headers included:
#include <winsock2.h>
#include <windows.h>
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
I have also added WS2_32.lib to the linker in Visual Studio 2010.
What else could cause this problem? I'm just trying to rewrite my simple UDP program to work under Windows.
Visual Studio can't find the type socklen_t. MSDN says that this function takes an int* as the last parameter, so cast to that.
The
socklen_t
type is defined inside of WS2tcpip.h in windows. This is not transitively included from winsock2.h (AFAICT). You'll need to include WS2tcpip.h manually in order to use thesocklen_t
type.