简体   繁体   English

套接字编程:将名称分配给端口号

[英]Socket programming:Assign name to port number

Is it possible to assign name to port number 是否可以为端口号分配名称

like 喜欢

localhost:8888 as localhost:xyz 本地主机:8888作为本地主机:xyz

localhost:9000 as localhost:abc localhost:9000作为localhost:abc

I want to hide port number from client side while giving them link 我想在给客户端链接的同时隐藏客户端的端口号

I have video streaming server (different streaming on different port) ...want to hide port number because any one can change port and will be able to see other stream 我有视频流服务器(不同端口上的不同流)...要隐藏端口号,因为任何人都可以更改端口并能够看到其他流

No, you can't do that. 不,你不能那样做。 The way TCP/IP works requires both ends to know the number of the port, just like they both have to know each other's IP addresses. TCP / IP的工作方式要求两端都知道端口号,就像它们都必须知道彼此的IP地址一样。

You need to pass the port numbers(source and destination port numbers) to the transportlayer. 您需要将端口号(源端口号和目标端口号)传递给传输层。 TCP uses the concept of Port multiplexing ie to use the different port numbers for different applications. TCP使用端口multiplexing的概念,即针对不同的应用程序使用不同的端口号。 Also if you check the TCP header, there are fields for source and destination port. 另外,如果您检查TCP标头,则存在用于源端口和目标端口的字段。

So you cannot change anything in the transport layer packet or TCP packet. 因此,您无法更改transport层数据包或TCP数据包中的任何内容。 But you always have control on the application layer, so you can create a mapping of port and names in your application and can use it. 但是您始终在application层上具有控制权,因此您可以在application中创建端口和名称的映射并可以使用它。 You can use data structure such as Map to store the port number and name mapping. 您可以使用诸如Map数据结构来存储端口号和名称映射。 This will allow you to use the port names in your application logic. 这将允许您在应用程序逻辑中使用端口名称。 But while sending the packet over the socket or to the TCP layer, make sure that you pass the port numbers instead of name. 但是,在通过套接字或TCP层发送数据包时,请确保传递端口号而不是名称。

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

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