C++ header files for UDP in Windows?
I have a linux applications which sends data over UDP protocol. It uses these header files:
#include <stdio.h>
/* standard C i/o facilities */
#include <stdlib.h>
/* needed for atoi() */
#include <unistd.h>
/* defines STDIN_FILENO, system calls,etc */
#include <sys/types.h> /* system data type definitions */
#include <sys/socket.h> /* socket specific definitions */
#include <netinet/in.h> /* INET con开发者_JAVA技巧stants and stuff */
#include <arpa/inet.h> /* IP address conversion stuff */
#include <netdb.h>
#include <string.h> /* for string and memset etc */
/* gethostbyname */
#include <iostream>
#include <fstream>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <opencv/cxcore.h>
I want to make a WIndows version of my app. But some of the above header files do not work in WIndows, especially those for UDP.
Which header files should I substitute them for in Windows (Visual Studio 2010)?
UPDATE:
Ok, so my header now looks like this:
#include <iostream>
#include <fstream>
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <winsock2.h>
I get this error when trying to compile (and many other similar errors):
Error 13 error C2011: 'fd_set' : 'struct' type redefinition c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winsock2.h 132 1 Client
At compile-time, you need to use Winsock2.h
instead of the Unix headers.
At link-time, include ws2_32.lib
to provide linkage to the required system DLL.
Comment out the include files that are "missing" or put them into the following:
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <winsock2.h>
#include <windows.h>
#else
// unix includes here
#endif
You don't need most of those includes. The only file you will need is winsock2.h and link with ws2_32.lib.
So, for all networking stuff, just include winsock2.h.
You want to #include winsock2.h. One peculiarity, you need to #include before including anything else, including :
#include <winsock2.h>
#include <windows.h>
精彩评论