A port multiplexing method and system compatible with multi-port use
Patent Information
- Application Number
- CN202211101750.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2022-08-22
- Filing Date
- 2022-09-09
- Publication Date
- 2026-08-21
- Estimated Expiration
- 2042-09-09
AI Technical Summary
[0004]在现有系统或大量使用开源代码的系统中,缺乏对端口资源的管理,极容易造成端口冲突;遇到这种情况一般需要增加端口管理并使用本地代理进行数据转发或者使用如grpc等自带端口复用的库对代码进行修改;
[0031]本申请实施例中在进行目标任务下发时生成目标任务识别码,并将目标任务识别码发送至执行目标任务的客户机与服务器,并对客户机与服务器进行信息配置;客户机根据目标任务识别码生成虚拟地址及虚拟端口,并与代理地址建立客户机映射表;服务器根据目标任务识别码生成虚拟地址及虚拟端口,并与服务器地址及服务器端口建立服务器映射表;客户机根据客户机映射表建立第一channel,通过第一channel建立socket连接,并将第一channel信息发送至服务器;服务器根据服务器映射表建立第二channel,通过第一channel信息将第二channel与socket连接绑定为一个通信信道。可以看出,本申请在不修改业务代码的前提下通过增加虚拟端口的概念,能够同时兼容通信数据量大以及旧系统的场景,有效的解决复杂系统在多场景下的应用。
Smart Images

Figure CN116418852B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communications, and in particular to a port multiplexing method and system compatible with multiple ports. Background Technology
[0002] System or program communication clients uniquely identify servers and establish communication channels with them using IP addresses and ports. Establishing a communication channel requires different tasks or services within the same process to listen on different ports; otherwise, the program will encounter port conflict exceptions. Cross-domain systems often involve intermediaries and are systems with limited port resources.
[0003] Systems that communicate through a gateway only have a limited number of available ports. Docker machines that do not have local area network IPs between different host machines typically communicate through ports mapped by the host machine. Multiple Docker machines may exist on the host machine at the same time, so port usage is also limited.
[0004] In existing systems or systems that heavily utilize open-source code, the lack of port resource management can easily lead to port conflicts. In such cases, it is generally necessary to add port management and use a local proxy for data forwarding, or modify the code using a library with built-in port multiplexing, such as gRPC.
[0005] However, existing port management modules incur costs for managing multi-task port usage, and the additional data forwarding process by the proxy process incurs performance losses, making them unsuitable for scenarios with large amounts of communication data. Modifying the code using libraries like gRPC that have built-in port multiplexing involves extensive modifications to the business system and has poor compatibility with older systems. Summary of the Invention
[0006] Based on this, the embodiments of this application provide a port multiplexing method and system compatible with multiple port usage, which solves the problems existing in the prior art.
[0007] Firstly, a port multiplexing method compatible with multiple port usage is provided, the method comprising:
[0008] When the target task is issued, a target task identification code is generated and sent to the client and server that execute the target task, and information is configured for the client and server.
[0009] The client generates a virtual address and virtual port based on the target task identifier and establishes a client mapping table with the proxy address; the server generates a virtual address and virtual port based on the target task identifier and establishes a server mapping table with the server address and server port.
[0010] The client establishes a first channel according to the client mapping table, establishes a socket connection through the first channel, and sends the first channel information to the server; the server establishes a second channel according to the server mapping table, and binds the second channel to the socket connection as a communication channel through the first channel information, wherein the communication channel is used to realize communication between the client and the server.
[0011] Optionally, there can be multiple servers executing the target task, and the information configuration for the client and the server includes:
[0012] Use proxy information and / or corresponding server information to distinguish different servers that perform the target task.
[0013] Optionally, the client establishes a first channel based on the client mapping table, and establishes a socket connection through the first channel, including:
[0014] The client establishes a first channel based on the virtual address and virtual port, using the virtual port as the name of the first channel, and establishes a socket connection based on the virtual address and virtual port.
[0015] Optionally, the server establishes a second channel based on the server mapping table, including:
[0016] A second channel is established based on the virtual address and virtual port in the server mapping table, wherein the virtual port is used as the name of the second channel.
[0017] Optionally, the second channel is bound to the socket connection as a communication channel using the first channel information, including:
[0018] A first channel and a second channel with the same name are socket bound together; wherein, the information of the first channel includes the name of the first channel, which is generated by the client virtual port; the name of the second channel is generated by the server virtual port.
[0019] Secondly, a port multiplexing system compatible with multiple port usage is provided, the system comprising:
[0020] The distribution module is used to generate a target task identification code when distributing a target task, and send the target task identification code to the client and server executing the target task, and to configure the information of the client and the server.
[0021] The generation module is used by the client to generate a virtual address and virtual port based on the target task identification code, and to establish a client mapping table with the proxy address; the server generates a virtual address and virtual port based on the target task identification code, and to establish a server mapping table with the server address and server port.
[0022] The communication module is used for the client to establish a first channel according to the client mapping table, establish a socket connection through the first channel, and send the first channel information to the server; the server to establish a second channel according to the server mapping table, and bind the second channel to the socket connection as a communication channel through the first channel information, wherein the communication channel is used to realize communication between the client and the server.
[0023] Optionally, there can be multiple servers executing the target task. The distribution module configures information between the client and the server, including:
[0024] Use proxy information and / or corresponding server information to distinguish different servers that perform the target task.
[0025] Optionally, in the communication module, the client establishes a first channel according to the client mapping table, and establishes a socket connection through the first channel, including:
[0026] The client establishes a first channel based on the virtual address and virtual port, using the virtual port as the name of the first channel, and establishes a socket connection based on the virtual address and virtual port.
[0027] Optionally, in the communication module, the server establishes a second channel based on the server mapping table, including:
[0028] A second channel is established based on the virtual address and virtual port in the server mapping table, wherein the virtual port is used as the name of the second channel.
[0029] Optionally, the communication module binds the second channel to the socket connection as a communication channel using the first channel information, including:
[0030] A first channel and a second channel with the same name are socket bound together; wherein, the information of the first channel includes the name of the first channel, which is generated by the client virtual port; the name of the second channel is generated by the server virtual port.
[0031] In this embodiment, a target task identification code is generated when the target task is issued, and the target task identification code is sent to the client and server executing the target task. Information configuration is performed on the client and server. The client generates a virtual address and virtual port based on the target task identification code and establishes a client mapping table with the proxy address. The server generates a virtual address and virtual port based on the target task identification code and establishes a server mapping table with the server address and server port. The client establishes a first channel based on the client mapping table, establishes a socket connection through the first channel, and sends the first channel information to the server. The server establishes a second channel based on the server mapping table and binds the second channel to the socket connection as a communication channel through the first channel information. It can be seen that this application, without modifying the business code, can simultaneously accommodate scenarios with large communication data volumes and legacy systems by adding the concept of virtual ports, effectively solving the application of complex systems in multiple scenarios. Attached Figure Description
[0032] To more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings in the following description are merely exemplary, and those skilled in the art can derive other embodiments based on the provided drawings without creative effort.
[0033] Figure 1 A flowchart of a port multiplexing method compatible with multiple port usage is provided in an embodiment of this application;
[0034] Figure 2 This application provides a block diagram of a port multiplexing system compatible with multiple port usage. Detailed Implementation
[0035] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0036] In the description of this invention, unless otherwise stated, "a plurality of" means two or more. The terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are intended to distinguish the objects they refer to. For schemes with a sequential flow, this terminology need not be understood as describing a specific order or sequence; for schemes with device structures, this terminology does not distinguish between matters of importance or positional relationships.
[0037] Furthermore, the terms “comprising,” “having,” and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units that are expressly listed, but may also include other steps or units that are not expressly listed but are inherent to these processes, methods, products, or apparatuses, or steps or units added based on further optimizations of the inventive concept.
[0038] Within a typical local area network (LAN), port resources are unrestricted, and different algorithms and tasks use different ports to distinguish themselves. As long as different algorithms and tasks use different ports at the business layer, the system can run normally. However, when the system runs in environments with limited port resources, such as cross-domain environments, port usage becomes severely restricted, and it may even fail to function properly. This invention effectively solves the above problems without modifying the business code. By adding the concept of virtual ports and an intermediate mapping layer, it can simultaneously accommodate the scenarios existing in the prior art, effectively solving the application of complex systems in multiple scenarios.
[0039] For details, please refer to Figure 1 The diagram illustrates a flowchart of a port multiplexing method compatible with multiple port usage provided in an embodiment of this application. The method may include the following steps:
[0040] S1 generates a target task identification code when the target task is issued, sends the target task identification code to the client and server that execute the target task, and configures the client and server information.
[0041] In a normal communication mode, the two communicating parties only need to obtain a pair of information—ip:port—to communicate. However, in systems with limited ports, there is usually an intermediate gateway that restricts port resources. Therefore, in this embodiment, a task information and three pairs of communication information are defined. The task_id and IP are of string type, and the port is of u32 type.
[0042] First, the specific definitions in the embodiments of this application will be explained:
[0043] 1) task_id (target task identifier): A random ID generated by the system when issuing a task. The client and server obtain the same task_id for the same task.
[0044] 2) server_ip (server address) and server_port (server port): The IP address and port that the server listens on. The number of server addresses is limited and fixed, so they can be statically configured.
[0045] 3) proxy_ip and proxy_port: intermediate proxy addresses, such as gateway address or host machine address, etc.
[0046] 4) virtual_ip (virtual address) and virtual_port (virtual port): virtual_ip is equal to tmp_id, and virtual_port is equal to the hash value of tmp_id modulo the maximum value of u32; tmp_id requires two dimensions of information to generate. The vertical dimension uses task_id to distinguish different tasks, and the horizontal dimension can use proxy information or information that can distinguish different servers, etc., to distinguish different target machines in the same task.
[0047] S2, the client generates a virtual address and virtual port based on the target task identification code, and establishes a client mapping table with the proxy address; the server generates a virtual address and virtual port based on the target task identification code, and establishes a server mapping table with the server address and server port.
[0048] S3, the client establishes a first channel according to the client mapping table, establishes a socket connection through the first channel, and sends the first channel information to the server; the server establishes a second channel according to the server mapping table, and binds the second channel to the socket connection as a communication channel through the first channel information.
[0049] The communication channel is used to enable communication between the client and the server. The client establishes a first channel based on a virtual address and a virtual port, using the virtual port as the first channel name, and establishes a socket connection based on the virtual address and virtual port. A second channel is established based on the virtual address and virtual port in the server's mapping table, using the virtual port as the second channel name.
[0050] In this embodiment, the sockets between the two communicating parties can be successfully established. However, different services on a server use the same listening port and cannot be distinguished from each other. Therefore, the concepts of channel and channel_name are introduced. One channel represents one service. For the same task, since the task_id is the same and the virtual_port is known to each other, the virtual_port is used as the channel_name.
[0051] In this embodiment of the application, the communication channel establishment process is as follows:
[0052] 1) Issue the task, task ID, and a list of proxy_ip and proxy_port for each proxy machine. If a machine does not have a code, the corresponding position in the list will be empty, and an index will be issued to indicate the position of the machine's proxy address in the list.
[0053] 2) The server finds its own proxy address, and then retrieves the server_ip and server_port from the configuration based on the proxy address;
[0054] 3) The server generates virtual_ip and virtual_port based on task_id, and establishes a mapping between them and server_ip and server_port;
[0055] 4) The server continuously listens for server_ip and server_port in the background, waiting for the client to establish a connection;
[0056] 5) The client generates virtual_ip and virtual_port based on task_id and establishes a mapping with the proxy address;
[0057] The above steps complete the establishment of the mapping tables for both the client and the server, and the server is in a connection listening state. Next, the communication channel will be established.
[0058] 6) The client business layer uses virtual_ip and virtual_port to create a new channel, uses virtual_port as the channel_name, and retrieves the ip:port from their respective mapping tables to establish a socket connection;
[0059] 7) The client channel sends the channel_name to the server; at this point, the client channel is already bound to the socket, while the server socket is in a detached state and holds the channel_name.
[0060] 8) The server-side business layer uses virtual_ip and virtual_port to create a new channel, uses virtual_port as the channel_name, retrieves the actual listening object from the mapping table, and registers itself to the listening object. The backend binds channels with the same channel_name and detached sockets together.
[0061] 9) Once the channel is established, the client sends data to the server.
[0062] The following is an optional embodiment applied to the above method, specifically:
[0063] There are three machines running an algorithm. During the process, one client and two servers are required. The proxy addresses of the two servers are proxy1.com:444 and proxy2.com:444. The address proxied to the server is 0.0.0.0:8080. The task_id for this task is task1. The roleid is used to indicate the proxy address when the machine is acting as a server.
[0064] S1, Task Assignment:
[0065] 1) The client receives the following parameters:
[0066] {task_id:task1,roleid:0,iplist:[null,proxy1.com:444,proxy2.com:444]}, since the client roleid is 0 and there is no proxy address, the 0th bit of iplist is set to null;
[0067] 2) The parameters received by server1 are:
[0068] {task_id:task1,roleid:1,iplist:[null,proxy1.com:444,proxy2.com:444]};
[0069] 3) server2 received the following parameters:
[0070] {task_id:task1,roleid:2,iplist:[null,proxy1.com:444,proxy2.com:444]};
[0071] S2, generate virtual information and establish a mapping table:
[0072] 1) The client needs to establish a mapping to server1 and server2. Either task_id+roleId or task_id+proxy address can be used. Here, task_id+roleId is used. For the server with roleid of 1, virtual_ip and virtual_port are generated. Since virtual_port is the result of virtual_ip hash, virtual_port1 is used here to replace the virtual information in the mapping table for ease of demonstration.
[0073] 2) server1 needs to establish a mapping of the listening address. It obtains proxy1.com:444 through roleid, and finds the listening address 0.0.0.0:8080 through the configuration of proxy1.com:444. It then generates the virtual information virtual_port1 as above.
[0074] 3) Similarly, set the listening address for server2 to 0.0.0.0:8080, and generate the virtual information virtual_port2 as above;
[0075] The client mapping table is as follows:
[0076] virtual_port1 proxy1.com:444 virtual_port2 proxy2.com:444
[0077] The mapping table for server1 is as follows:
[0078] virtual_port1 0.0.0.0:8080
[0079] The server2 mapping table is as follows:
[0080] virtual_port2 0.0.0.0:8080
[0081] 4) The mapping relationship from proxy1.com:444 to server1's 8080 port is predetermined in devices such as the gateway;
[0082] S3, Establish a communication channel:
[0083] 1) The client initiates the connection. For example, if server1 initiates the connection: a new channel is created and the channel_name is set to virtual_port1. The proxy address proxy1.com:444 is obtained through virtual_port1 and a socket connection is established. Then, the channel_name is sent to the client.
[0084] 2) Server1 creates a new channel, sets the channel_name to virtual_port1, and obtains the object listening at address 8080 from the mapping table through virtual_port1. Based on the channel_name, it obtains the socket in a detached state with the same channel_name. From this point on, the client successfully establishes a connection with the relevant channel of server1 and can send and receive data normally.
[0085] In summary, this application uses multi-dimensional information to generate virtual information such as virtual_ip and virtual_port; for example, virtual_port is generated using the two-dimensional information of task_id and role_id as mentioned above.
[0086] An m:n mapping relationship is established between virtual information and real information, and the virtual information is used as the channel_name to establish a two-way communication channel. As mentioned above, an m:n relationship is established between virtual_port and proxy_port. In special scenarios, when there is only one gateway proxy, a many-to-one mapping relationship is established, which effectively utilizes system resources.
[0087] like Figure 2 This application also provides a port multiplexing system 200 compatible with multiple port usage. System 200 includes:
[0088] The distribution module 201 is used to generate a target task identification code when distributing the target task, send the target task identification code to the client and server executing the target task, and configure information for the client and server.
[0089] The generation module 202 is used for the client to generate a virtual address and virtual port based on the target task identification code, and to establish a client mapping table with the proxy address; the server to generate a virtual address and virtual port based on the target task identification code, and to establish a server mapping table with the server address and server port.
[0090] The communication module 203 is used for the client to establish a first channel according to the client mapping table, establish a socket connection through the first channel, and send the first channel information to the server; the server to establish a second channel according to the server mapping table, and bind the second channel and the socket connection to a communication channel through the first channel information, wherein the communication channel is used to realize communication between the client and the server.
[0091] In an optional embodiment of this application, there may be multiple servers executing the target task, and the distribution module configures information between the client and the server, including:
[0092] Use proxy information and / or corresponding server information to distinguish different servers that perform the target task.
[0093] In an optional embodiment of this application, the client in the communication module 203 establishes a first channel according to the client mapping table and establishes a socket connection through the first channel, including: the client establishes the first channel according to the virtual address and virtual port, wherein the virtual port is used as the name of the first channel, and establishes a socket connection according to the virtual address and virtual port.
[0094] In an optional embodiment of this application, the server in the communication module 203 establishes a second channel according to the server mapping table, including: establishing a second channel according to the virtual address and virtual port in the server mapping table, wherein the virtual port is used as the name of the second channel.
[0095] In an optional embodiment of this application, the communication module 203 binds the second channel to the socket connection as a communication channel through the first channel information, including: binding the first channel and the second channel with the same name to the socket; wherein, the first channel information includes the first channel name, which is generated through the client virtual port; the second channel name is generated through the server virtual port.
[0096] The port multiplexing system compatible with multiple ports provided in this application is used to implement the aforementioned port multiplexing method compatible with multiple ports. Specific limitations of the port multiplexing system compatible with multiple ports can be found in the limitations of the port multiplexing method compatible with multiple ports described above, and will not be repeated here. Each part of the aforementioned port multiplexing system compatible with multiple ports can be implemented wholly or partially through software, hardware, or a combination thereof. The aforementioned modules can be embedded in or independent of the processor in the device in hardware form, or stored in the memory of the device in software form, so that the processor can call and execute the operations corresponding to the above modules.
[0097] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0098] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. A port multiplexing method compatible with multiple port usage, characterized in that, The method includes: When the target task is issued, a target task identification code is generated and sent to the client and server that execute the target task, and information is configured for the client and server. The client generates a virtual address and virtual port based on the target task identifier and establishes a client mapping table with the proxy address; the server generates a virtual address and virtual port based on the target task identifier and establishes a server mapping table with the server address and server port. The client establishes a first channel according to the client mapping table, establishes a socket connection through the first channel, and sends the first channel information to the server; the server establishes a second channel according to the server mapping table, and binds the second channel to the socket connection as a communication channel through the first channel information, wherein the communication channel is used to realize communication between the client and the server; There can be multiple servers executing the target task. The feature is that the information configuration of the client and the server includes: using proxy information and / or corresponding server information to distinguish different servers executing the target task.
2. The method according to claim 1, characterized in that, The client establishes a first channel based on the client mapping table, and establishes a socket connection through the first channel, including: The client establishes a first channel based on the virtual address and virtual port, using the virtual port as the name of the first channel, and establishes a socket connection based on the virtual address and virtual port.
3. The method according to claim 1, characterized in that, The server establishes a second channel based on the server mapping table, including: A second channel is established based on the virtual address and virtual port in the server mapping table, wherein the virtual port is used as the name of the second channel.
4. The method according to claim 1, characterized in that, The second channel is bound to the socket connection as a communication channel using the first channel information, including: A first channel and a second channel with the same name are socket bound together; wherein, the information of the first channel includes the name of the first channel, which is generated by the client virtual port; the name of the second channel is generated by the server virtual port.
5. A port multiplexing system compatible with multiple port usage, characterized in that, The system includes: The distribution module is used to generate a target task identification code when distributing a target task, and send the target task identification code to the client and server executing the target task, and to configure the information of the client and the server. The generation module is used by the client to generate a virtual address and virtual port based on the target task identification code, and to establish a client mapping table with the proxy address; the server generates a virtual address and virtual port based on the target task identification code, and to establish a server mapping table with the server address and server port. The communication module is used for the client to establish a first channel according to the client mapping table, establish a socket connection through the first channel, and send the first channel information to the server; the server to establish a second channel according to the server mapping table, and bind the second channel to the socket connection as a communication channel through the first channel information, wherein the communication channel is used to realize communication between the client and the server; The distribution module configures information for the client and the server, including: using proxy information and / or corresponding server information to distinguish different servers that perform the target task.
6. The system according to claim 5, characterized in that, In the communication module, the client establishes a first channel based on the client mapping table, and establishes a socket connection through the first channel, including: The client establishes a first channel based on the virtual address and virtual port, using the virtual port as the name of the first channel, and establishes a socket connection based on the virtual address and virtual port.
7. The system according to claim 5, characterized in that, In the communication module, the server establishes a second channel based on the server mapping table, including: A second channel is established based on the virtual address and virtual port in the server mapping table, wherein the virtual port is used as the name of the second channel.
8. The system according to claim 5, characterized in that, The communication module binds the second channel to the socket connection as a communication channel using the first channel information, including: A first channel and a second channel with the same name are socket bound together; wherein, the information of the first channel includes the name of the first channel, which is generated by the client virtual port; the name of the second channel is generated by the server virtual port.
Citation Information
Patent Citations
SG10202251580B