gpt4 book ai didi

file - 套接字描述符基本上是文件描述符的同义词吗?

转载 作者:行者123 更新时间:2023-12-03 11:58:11 24 4
gpt4 key购买 nike

来自:http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html

So when you want to communicate with another program over the Internetyou're gonna do it through a file descriptor, you'd better believe it.

“Where do I get this file descriptor for network communication, Mr.Smarty-Pants?” is probably the last question on your mind right now,but I'm going to answer it anyway: You make a call to the socket()system routine. It returns the socket descriptor, and you communicatethrough it using the specialized send() and recv() (man send, manrecv) socket calls.

“But, hey!” you might be exclaiming right aboutnow. “If it's a file descriptor, why in the name of Neptune can't Ijust use the normal read() and write() calls to communicate throughthe socket?” The short answer is, “You can!” The longer answer is,“You can, but send() and recv() offer much greater control over yourdata transmission.”


由于套接字是UNIX中不同进程之间的一种通信方式,

UNIX中不同进程之间的所有通信都是通过读写文件来完成的,

文件描述符是一个整数,唯一表示操作系统中的打开文件。
那么,套接字描述符基本上是文件描述符吗?
还是套接字描述符基本上是两个程序之间已建立链接的唯一标识?

两者之间有什么区别?

最佳答案

这里有几个问题,但是对所有问题的答案都是相同的。在Unix,Linux等上,套接字描述符是文件描述符。这就是为什么您可以使用read()以及write()和close()的原因。

在Windows上不是,而且您不能。

关于file - 套接字描述符基本上是文件描述符的同义词吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22374196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com