简体   繁体   English

是否可以使用具有不同端口的相同 ip 地址,每个端口用于特定协议(TCP 和 UDP)?

[英]Is it possible to use the same ip address with different ports, each port for a specific protocol (TCP and UDP)?

Is it possible that one application uses the same Ip @ and connects to three different applications using different protocols TCP and UDP?是否有可能一个应用程序使用相同的 Ip @ 并使用不同的协议 TCP 和 UDP 连接到三个不同的应用程序?

Best regards,此致,

Port spaces are different for TCP and UDP, as they are different protocols. TCP 和 UDP 的端口空间不同,因为它们是不同的协议。 Nothing (but the range of values, that goes in both from 1 to 65535) makes them interchangeable.没有什么(但值的范围,从 1 到 65535)使它们可以互换。 But many services that interoperate in both TCP & UDP select the same port number (if available, look in IANA for assigned numbers) to the same service.但是在 TCP 和 UDP select 中互操作的许多服务将相同的端口号(如果可用,请在 IANA 中查找分配的号码)到相同的服务。 Anyway, being TCP a connection oriented, reliable protocol, without frame delimitation and UDP unreliable, packet delimited protocol, it is no much sense to use udp for some protocol if it is only specified for TCP media, or the reverse. Anyway, being TCP a connection oriented, reliable protocol, without frame delimitation and UDP unreliable, packet delimited protocol, it is no much sense to use udp for some protocol if it is only specified for TCP media, or the reverse.

Both TCP & UDP can listen for packets in any (or all) of the interfaces of the host, so in order to allow several different UDP/TCP services to run in each interface, the protocols were specified with a port multiplexing/demultiplexing feature (the port numbers) This is what makes the kernel to decide to which socket to deliver the data comming from the network (demultiplexing) and what allows all packets (multiplexing) to share the same medium (the network wire) TCP 和 UDP 都可以在主机的任何(或所有)接口中侦听数据包,因此为了允许多个不同的 UDP/TCP 服务在每个接口中运行,协议指定了端口复用/解复用功能(端口号)这就是让 kernel 决定将来自网络的数据(解复用)传递到哪个套接字以及允许所有数据包(复用)共享相同介质(网络线)的原因

Yes, one application can have several network connections using different ports and protocols all being on the same IP address.是的,一个应用程序可以有多个使用不同端口和协议的网络连接,它们都在同一个 IP 地址上。

Just open several sockets with their specific options.只需打开几个 sockets 及其特定选项即可。

The 'tricky' thing is going to be making sure that all sockets are read from and written to. “棘手”的事情是确保所有 sockets 都被读取和写入。 You may need threads.您可能需要线程。

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

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