Windows 中 UDP 的 C++ 头文件?

标签 c++ visual-c++ sockets udp winsock

我有一个通过 UDP 协议(protocol)发送数据的 linux 应用程序。它使用这些头文件:

#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 constants 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> 

我想制作我的应用程序的 WIndows 版本。但是上面的一些头文件在 WIndows 中不工作,尤其是那些 UDP 的头文件。

我应该在 Windows (Visual Studio 2010) 中替换哪些头文件?

更新:

好的,所以我的标题现在看起来像这样:

#include <iostream>
#include <fstream>
#include "stdafx.h"

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

#include <winsock2.h>

我在尝试编译时遇到此错误(以及许多其他类似错误):

Error   13  error C2011: 'fd_set' : 'struct' type redefinition  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winsock2.h  132 1   Client

最佳答案

在编译时,您需要使用 Winsock2.h 而不是 Unix header 。

在链接时,包含 ws2_32.lib 以提供到所需系统 DLL 的链接。

关于Windows 中 UDP 的 C++ 头文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4432989/

相关文章:

java - 如何设计具有许多持久连接的服务器

c++ - 更改列表项

C++命名空间名称隐藏

c++ - CDialog *m_pages[6]; vs CDialog *m_pages = new CDialog[6];?

c++ - 实现嵌套在模板类中的类的成员函数

c# - 与localhost C#的双向通信

php - 连接后保持 PHP 服务器套接字处于事件状态

c++ - 有条件地将文件添加到 C++ 项目中的库

c++ - 如何正确推断模板的返回类型?

c++ - 将 double 值格式化为小数点后一位