为什么我们不能使用进程ID来获取要绑定的端口 [英] why cannot we use process id insted of taking the port we are binding

查看:98
本文介绍了为什么我们不能使用进程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屋!

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