为什么我们不能使用进程 ID 来获取我们绑定的端口 [英] why cannot we use process id insted of taking the port we are binding
本文介绍了为什么我们不能使用进程 ID 来获取我们绑定的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我们不能使用进程 ID 来获取我们在套接字编程中绑定的端口.在套接字编程中,我们创建套接字并获取套接字描述符,然后绑定到特定端口.对于多个连接,为什么我们不使用进程 ID,因为所有连接也是返回进程 ID 的进程?
why cannot we use process id insted of taking the port we are binding in socket programming. in socket programming we create socket and get a socket descriptor and we bind to a specific port .for multiple connection why are we not using the process id as all the connection are also a process returning the processs id?
推荐答案
这是一个有趣的想法,但我认为它会引发一些问题:
It's an interesting idea, but I think it would raise a few problems:
- 您如何知道要连接到哪个进程 ID?
- 如果您想在同一个进程中监听多个端口"怎么办?您只有一个进程 ID.
- IPv4 和 IPV6 为端口 ID 分配 16 位,但进程 ID 通常是 32 位(或更大)值,因此不适合
- 有许多程序没有网络方面的内容,并且不想要一个.自动实例化到它们的网络通信路径会是一个潜在的安全问题吗?
- 您可以做的一个技巧(尤其是使用 UDP 多播或广播)是让多个程序在同一个端口上侦听(通过 SO_REUSEPORT),这样当任何人向该端口发送 UDP 数据包时,所有程序都会收到它.如果程序必须使用它们的(唯一的)进程 ID 号作为端口号,那么这个技巧将很难或不可能.
这篇关于为什么我们不能使用进程 ID 来获取我们绑定的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文