简体   繁体   English

Windows最低级别的套接字编程?

[英]Windows lowest level socket programming?

I'm having a little bit of confusion regarding how low-level winsock is? 我对低水平的winsock有点困惑? I am wanting to write a VERY basic client-server program on windows. 我想在Windows上编写一个非常基本的客户端-服务器程序。 I don't really wish to use a bloated TCP or even UDP, just something extremely basic and low latency. 我真的不希望使用a肿的TCP甚至UDP,而只是使用一些非常基本且延迟很短的东西。 Would winsock be ideal for this? Winsock对此是否理想? Or is winsock the same as the windows network functions, just all packaged up (and possibly slower)? 还是Winsock与Windows网络功能相同,只是打包了(可能更慢)? Would I be better just using PInvoke on the native windows networking functions? 仅在本机Windows网络功能上使用PInvoke会更好吗?

Winsock, TCP, UDP, and any well received networking library built on top of these are all going to be comparable performance wise. Winsock,TCP,UDP以及在这些基础之上构建的任何广受欢迎的网络库都将在性能上具有可比性。

Use whichever one is easiest to get your work done. 使用最容易完成的工作。

First of all, it's possible to write completely new protocol w/o implementing network driver. 首先,可以编写不带网络驱动程序的全新协议。 For this you have raw sockets . 为此,您有原始套接字 On desktop Windows they are very limited (find "limitations"). 在桌面Windows上,它们非常有限 (找到“限制”)。

It's possible, but not recommended. 有可能,但不建议这样做。 Don't reinvent the wheel and choose between UDP and TCP until you're completely sure you need something more sophisticated (but not simpler). 在完全确定需要更高级的东西(而不是更简单的东西)之前,不要重新发明轮子并在UDP和TCP之间进行选择。

To send data over network (as opposite to direct cable link between two computers) you need IP protocol. 要通过网络发送数据(与两台计算机之间的直接电缆链接相反),您需要IP协议。 To dispatch your data to right application you need transport protocol (UDP, TCP and others). 要将数据分发到正确的应用程序,您需要传输协议(UDP,TCP和其他协议)。 UDP is almost the simplest possible one because that's was its main design goal. UDP几乎是最简单的一种,因为这是它的主要设计目标。 UDP provides additional addressing (port number in addition to IP address to deliver your data to right socket), packet boundaries ("length" field) and optional checksum. UDP提供其他寻址(除了IP地址以外的端口号,用于将数据传送到正确的套接字),数据包边界(“长度”字段)和可选的校验和。 That's all and that's the minimum feature list. 仅此而已,这是最低功能列表。 Take it and implement everything you need over UDP. 采取它并通过UDP实现所需的一切。

Next, if you need to be sure that your packets are delivered instead of silently dropped somewhere on the way (reliability), delivered in right order, if you'd like to know that somebody still listen to you on opposite end (connectivity) and other things implemented by best specialists, with hardware adapted to this implementation, tested by millions during decades, with lots of documentation, available on almost all possible platforms - use TCP. 接下来,如果您需要确保您的数据包已传递,而不是在途中被静默丢弃(可靠性),请以正确的顺序传递,如果您想知道有人仍然在另一端收听您的消息(连接性),并且最好的专家实施的其他事情,以及与该实现相适应的硬件,数十年来经过数百万次测试,并提供了几乎所有可能的平台上可用的大量文档-使用TCP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM