在 windows 上使用 sys/socket.h 函数 [英] Using sys/socket.h functions on windows

查看:308
本文介绍了在 windows 上使用 sys/socket.h 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows 中使用 socket.h 函数.基本上,我目前正在查看 https://beej 上的示例代码.us/guide/bgnet/html/multi/clientserver.html#datagram.我知道 socket.h 是一个 Unix 函数——无论如何我可以在编译此示例代码时轻松模拟该环境吗?不同的 IDE/编译器会改变什么吗?

I'm attempting to utilize the socket.h functions within Windows. Essentially, I'm currently looking at the sample code at https://beej.us/guide/bgnet/html/multi/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 环境,这可能是最好的,因为代码很可能在 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.

谢谢.

推荐答案

您有两个选择:

  1. 使用 Cygwin(Unix 仿真库).
  2. 端口到 Winsock(Windows 标准库).

Cygwin:允许您编译大部分未改动的 Unix 源代码,但将您与 Cygwin 仿真库联系起来.这有两个含义:一般性能——不仅仅是网络——可能不是最佳的;并且目标环境必须(在运行时)安装了 Cygwin DLL.

Cygwin: lets you compile your Unix sources mostly untouched, but ties you to the Cygwin emulation library. This have two implications: general performance -no only network- will probably be less than optimal; and the target environment must have (at run time) the Cygwin DLL installed.

Winsock:这需要您将 sys/socket.h(BSD 套接字库,TCP/IP 堆栈的 UNIX 标准)替换为 winsock2.h,并重写代码的某些部分 - 不多,但有一些.

Winsock: this 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:

winsock 和 BSD 套接字实现之间的差异

关于 Cygwin 的一些问题[Windows 中的 Linux](套接字、线程、其他编程和外壳问题)

Winsock 示例?

这篇关于在 windows 上使用 sys/socket.h 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆