使用SYS /在Windows socket.h中的功能 [英] Using sys/socket.h functions on windows
问题描述
我试图利用Windows中socket.h中的功能。从本质上讲,我目前在看样品code。在<一个href=\"http://beej.us/guide/bgnet/output/html/multipage/clientserver.html#datagram\">http://beej.us/guide/bgnet/output/html/multipage/clientserver.html#datagram.据我所知,socket.h中是一个Unix函数 - 反正是有在编译这个样本code我可以很容易模仿的环境?做了不同的IDE /编译器改变什么?
I'm attempting to utilize the socket.h functions within Windows. Essentially, I'm currently looking at the sample code at http://beej.us/guide/bgnet/output/html/multipage/clientserver.html#datagram. I understand that socket.h is a Unix function -- is there anyway I can easily emulate that environment while compiling this sample code? Does a different IDE / compiler change anything?
另外,我想,我需要利用虚拟化Linux环境中,这可能是最好的,反正为code将最有可能在UNIX环境下运行。
Otherwise, I imagine that I need to utilize a virtualized Linux environment, which may be best anyways as the code will most likely be running in a UNIX environment.
感谢。
推荐答案
您有两种选择:
- 使用 Cygwin的 (Unix的仿真库)。
- 港<一个href=\"http://msdn.microsoft.com/en-us/library/ms740673%28v=VS.85%29.aspx\">Winsock (Windows标准库)。
第一个选项可以让你编译你的Unix源大多是不变的,但绑你在Cygwin仿真库(在运行时意味着两件事:性能一般只-no网络 - 将可能达不到最佳;而运行环境必须有Cygwin的DLL可用)。第二种选择,需要你来代替
,并重写code的某些部分 - 不是很多,但一些。 SYS / socket.h中
(BSD套接字库,用于TCP / IP协议栈UNIX标准)winsock2.h
The first option allows you to compile your Unix sources mostly untouched, but ties you to the Cygwin emulation library (which implies two things at runtime: general performance -no only network- will probably be less than optimal; and the running environment must have the Cygwin DLL available). The second alternative requires you to replace sys/socket.h
(BSD sockets library, UNIX standard for the TCP/IP stack) with winsock2.h
, and rewrite some parts of the code -not much, but some.
提供有价值信息的一些相关问题:
Some related questions with valuable info:
<一个href=\"http://stackoverflow.com/questions/1383286/differences-between-winsock-and-bsd-socket-implementations\">Differences Winsock和BSD套接字实现之间
<一个href=\"http://stackoverflow.com/questions/2087435/cygwin-socket-thread-other-programming-issues-some-question-about-cygwin\">Some关于Cygwin的[的Linux在Windows(插座,线,其他的编程和外壳的问题)
这篇关于使用SYS /在Windows socket.h中的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!