A one-way transmission communication method and system based on the KCP protocol

By setting up an address learning module and a channel separation module around the KCP protocol stack, the input and output of the KCP protocol stack instance are bound to the UDP endpoint of the physical unidirectional link. This solves the problem that the KCP protocol cannot run on unidirectional transmission devices, realizes a reliable logical bidirectional session, reduces development and maintenance costs, and supports automatic backhaul establishment in dynamic IP and NAT scenarios.

CN123123032APending Publication Date: 2026-11-17SHANDONG ZHONGWANG YUNAN INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611618495.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-20
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

The existing KCP protocol cannot run directly on unidirectional transmission devices, and existing solutions are costly to develop, incompatible with the existing KCP ecosystem, and cannot automatically establish a return path in dynamic IP or NAT scenarios.

Method used

By setting up an address learning module and a channel separation module around the KCP protocol stack, the input of the KCP protocol stack instance is bound to the UDP receiving endpoint of a physical unidirectional link, and the output is bound to the UDP sending endpoint of another physical unidirectional link, forming a logical bidirectional session and realizing reliability mechanisms such as ARQ retransmission and sliding window.

Benefits of technology

Without modifying the core algorithm of the KCP protocol, reliable data transmission in a physically unidirectional isolated environment is achieved, reducing development and maintenance costs and supporting automatic backhaul establishment in dynamic IP and NAT scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure SMS_1
    Figure SMS_1
Patent Text Reader

Abstract

This invention relates to the field of data communication technology, specifically to a unidirectional transmission communication method and system based on the KCP protocol. The method includes: a server creating a first UDP receiving endpoint and a first UDP sending endpoint; receiving the first KCP data packet sent by the client via a forward optical gate through the receiving endpoint, and obtaining its source network address; setting the destination address of the first UDP sending endpoint to the source network address; extracting the KCP session identifier from the data packet, creating a corresponding KCP protocol stack instance if one does not exist, and binding the input callback of the instance to the receiving endpoint and the output callback to the sending endpoint; inputting the data packet into the instance for processing, so that acknowledgment packets and retransmission packets are sent to the client via a reverse optical gate, forming a physically unidirectional and logically bidirectional reliable communication closed loop. This invention does not require modification of the KCP core protocol, automatically establishes a backhaul path, allows multiple sessions to share a port, reduces resource consumption, and achieves TCP-like reliable transmission.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data communication technology, and specifically to a one-way transmission communication method and system based on the KCP protocol. Background Technology

[0002] A unidirectional optical shutter (also known as a data diode) is a network isolation device that forces unidirectional data transmission at the physical layer. It is widely used in scenarios where high-security networks unidirectionally export data to low-security networks. In physically isolated networks composed of forward and reverse unidirectional optical shutters, reliable data transmission faces the following technical challenges: First, the standard TCP protocol is completely ineffective because it relies on bidirectional peer-to-peer communication and a three-way handshake closed-loop feedback; although the standard UDP protocol can transmit unidirectionally, it does not provide acknowledgment, retransmission, and order guarantee, and therefore cannot guarantee data integrity.

[0003] Second, the KCP protocol is a reliable transport protocol based on UDP, providing TCP-like reliability through mechanisms such as ARQ (Automatic Retransmission), sliding windows, and selective acknowledgment. However, existing KCP implementations all assume that the underlying network is a single bidirectional UDP channel, using the same UDP socket for data transmission and ACK reception. When the underlying network is a physical unidirectional link, although the forward data can reach the receiving end, the ACK packet generated by the receiving end cannot return to the sending end along the reverse physical path, causing the sending end to continuously time out and retransmit until the connection fails. Therefore, the standard KCP protocol cannot run directly on unidirectional transmission devices.

[0004] Third, to achieve reliable communication on unidirectional transmission devices, existing technologies typically employ a "dual optical gate + self-developed ARQ" solution. This involves deploying forward and reverse optical gates separately, with the self-developed ARQ protocol handling acknowledgment and retransmission on the two unidirectional links. This approach requires reimplementing a reliable transmission protocol stack similar to KCP, resulting in high development costs and incompatibility with the existing KCP ecosystem. Alternatively, a "front-end processor + UDP pass-through" approach is used, where the intermediate segment only performs UDP pass-through and lacks packet loss retransmission capabilities. None of these solutions decouple the KCP protocol's send / receive channels and bind them to two physically independent unidirectional links, nor do they provide any technical insights into adapting to unidirectional channels without modifying the core KCP algorithm. Furthermore, in this deployment mode, the sending end of the reverse link must know the receiving address of the receiving end in advance. Existing solutions rely on static configuration, making it difficult to automatically establish a return path in dynamic IP or NAT scenarios.

[0005] Therefore, without modifying the core algorithm of the KCP protocol, how to bind the input and output of the KCP protocol stack instance to two physically independent unidirectional links respectively, and automatically determine the reverse return address, so that the reliability mechanisms of KCP such as ARQ retransmission and sliding window can operate normally in a physically unidirectional isolated environment and provide reliable bidirectional communication services similar to TCP, is a technical problem that needs to be solved by the current technology. Summary of the Invention

[0006] To address the shortcomings of existing technologies, this invention provides a one-way transmission communication method and system based on the KCP protocol. It does not require modification of the KCP core protocol, automatically establishes a return path, allows multiple sessions to share a port, reduces resource consumption, and achieves TCP-like reliable transmission.

[0007] This invention is achieved through the following technical solution: A one-way transmission communication method based on the KCP protocol is provided, applicable to a physically isolated network environment containing forward one-way transmission devices and reverse one-way transmission devices, including: The server creates a first UDP receive endpoint and a first UDP send endpoint; the first UDP receive endpoint is connected to the output of the forward unidirectional transmission device to receive data packets sent by the client; the first UDP send endpoint is initially not specified with a destination address and is connected to the input of the reverse unidirectional transmission device to send data packets to the client. The server receives the first data packet from the client through the first UDP receiving endpoint, obtains the source network address of the first data packet, and sets the destination address of the first UDP sending endpoint to the source network address; The server inputs the data packets from the first UDP receiving endpoint into the KCP protocol stack instance for processing, and binds the output callback of the KCP protocol stack instance to the first UDP sending endpoint, so that the acknowledgment packets and retransmission packets generated by the KCP protocol stack instance are sent to the set source network address through the first UDP sending endpoint; The input of the KCP protocol stack instance comes only from the first UDP receiving endpoint, and the output is sent only through the first UDP sending endpoint. A logical bidirectional session is formed within the KCP protocol stack instance. On the physical link, the forward unidirectional transmission device carries the data packet transmission, and the reverse unidirectional transmission device carries the acknowledgment packet and retransmission packet transmission.

[0008] Furthermore, the server also maintains the address learning state α and the address storage area τ; When the first data packet is received when α=0, the following steps are executed: assign τ the source network address of the first data packet, set α to 1, and set the destination address of the first UDP sending endpoint to the source network address; When α=1, the server obtains the source network address of subsequent data packets. If the source network address is different from τ, the data packet is discarded. The transition of α from 0 to 1 is irreversible, and the target address of the first UDP sending endpoint remains unchanged after α is set to 1.

[0009] Furthermore, the server parses the KCP session identifier conv from the first 4 bytes of the data packet payload in network byte order; Query the session mapping table M using conv as the key; If no corresponding entry exists in M, a KCP protocol stack instance is created, the output callback function of the instance is bound to the first UDP sending endpoint, and the mapping relationship between conv and the KCP protocol stack instance is stored in M; If a corresponding entry already exists in M, then obtain the already created KCP protocol stack instance; The current data packet is input into the obtained KCP protocol stack instance for processing.

[0010] Furthermore, when multiple KCP protocol stack instances exist on the server side, the output callback functions of each KCP protocol stack instance are all bound to the same first UDP sending endpoint and share the same target address; the server only occupies one first UDP receiving port and one first UDP sending port for multiple concurrent KCP sessions.

[0011] Furthermore, the KCP protocol stack instance adopts the standard KCP protocol's send queue, receive queue, sliding window state, and retransmission timer without modifying the core KCP protocol algorithm. By setting up an address learning module and a channel separation module around the KCP protocol stack instance, the input channel of the KCP protocol stack instance is bound to the first UDP receiving endpoint, and the output callback of the KCP protocol stack instance is bound to the first UDP sending endpoint, thus achieving separation of the physical paths for sending and receiving.

[0012] Furthermore, before completing address learning through the first data packet, the server does not execute a handshake negotiation process independent of the KCP data payload, nor does it pre-configure the target address of the first UDP sending endpoint; the first data packet is a KCP protocol data segment, the payload of which contains the KCP session identifier conv; the server only completes the target address setting of the first UDP sending endpoint based on the source address of the KCP segment.

[0013] Furthermore, the client is the data sender, and the server is the data receiver. At least the following reliable transmission mechanisms must be maintained between the server's KCP protocol stack instance and the client's KCP protocol stack instance: ARQ Automatic Retransmission Request Mechanism: After the data sending side sends a segment, it starts a retransmission timer. If no corresponding ACK confirmation is received within the retransmission timeout period RTO, the segment is added back to the sending queue and retransmitted through the forward unidirectional transmission device. Timeout backoff mechanism: The timeout after retransmission is updated according to RTO×(1+β); Sliding window flow control mechanism and selective acknowledgment mechanism: The data receiving side carries acknowledgment information and selective acknowledgment information through ACK packets, and the data sending side only retransmits unacknowledged segments; In-order delivery mechanism: The data receiving side buffers and reorders out-of-order message segments, and delivers them to the upper-layer application in order after the messages are continuous.

[0014] Furthermore, the server provides standard send / recv read / write interfaces to upper-layer applications. The KCP protocol stack instance is responsible for data fragmentation, transmission, acknowledgment, and ordering, shielding the details of the send / receive path separation caused by forward and reverse unidirectional transmission devices, and presenting a TCP-like reliable bidirectional interaction mode to the outside world.

[0015] This invention also provides a reliable one-way transmission communication system based on the KCP protocol, applied in a physically isolated network environment containing forward one-way transmission devices and reverse one-way transmission devices, comprising: The client is configured with a second UDP sending endpoint and a second UDP receiving endpoint; the second UDP sending endpoint is connected to the input of the forward unidirectional transmission device and is used to send KCP data packets to the server; the second UDP receiving endpoint is connected to the output of the reverse unidirectional transmission device and is used to receive KCP acknowledgment packets and retransmission packets from the server. The server is configured with a first UDP receiving endpoint, a first UDP sending endpoint, an address learning module, and a KCP protocol stack instance. The first UDP receiving endpoint is connected to the output of the forward unidirectional transmission device and is used to receive KCP data packets from the client. The first UDP sending endpoint is connected to the input of the reverse unidirectional transmission device. Initially, no destination address is specified, and it is used to send KCP acknowledgment packets and retransmission packets to the client. The address learning module is connected to the first UDP receiving endpoint and the first UDP sending endpoint respectively. It is used to set the target address of the first UDP sending endpoint according to the source network address of the first KCP data packet received by the first UDP receiving endpoint, so that a reverse feedback link is formed between the first UDP sending endpoint and the second UDP receiving endpoint via the reverse unidirectional transmission device. The input channel of the KCP protocol stack instance is connected to the first UDP receiving endpoint, and the output callback is connected to the first UDP sending endpoint. This ensures that the data input of the KCP protocol stack instance comes only from the first UDP receiving endpoint, and the output is sent only through the first UDP sending endpoint. This forms a logical bidirectional session within the KCP protocol stack. On the physical network, the forward unidirectional transmission device carries the unidirectional transmission of data packets, and the reverse unidirectional transmission device carries the unidirectional transmission of acknowledgment packets and retransmission packets.

[0016] Furthermore, the address learning module also maintains the address learning state α and the address storage area τ; when α=0, in response to the first UDP receiving endpoint receiving the first KCP packet, τ is assigned the source network address of the KCP packet, α is set to 1, and the destination address of the first UDP sending endpoint is set to τ; when α=1, if the source network address of subsequent KCP packets is different from τ, they are discarded. The server also includes a session management module, which is used to parse the KCP session identifier conv from the first 4 bytes of the KCP packet payload in network byte order, query the session mapping table M with conv as the key, and if there is no corresponding entry in M, create a KCP protocol stack instance and bind the output callback of the instance to the first UDP sending endpoint, and store the mapping relationship between conv and the instance in M. If there is already a corresponding entry in M, reuse the already created KCP protocol stack instance. When multiple KCP protocol stack instances exist on the server side, the output callbacks of each KCP protocol stack instance are bound to the same first UDP sending endpoint and share the same target address. The server only maintains one first UDP receiving port and one first UDP sending port for all concurrent KCP sessions.

[0017] The beneficial effects of this invention are: This invention constructs a logical bidirectional session required for the normal operation of the KCP protocol by binding the first UDP receiving endpoint and the first UDP sending endpoint to the input and output of the same KCP protocol stack instance, respectively, on two physically independent unidirectional links: data packets arrive at the server via the forward unidirectional transmission device, and acknowledgment packets and retransmission packets return to the client via the reverse unidirectional transmission device. Therefore, the original ARQ retransmission, sliding window, selective acknowledgment, and in-order delivery mechanisms of the KCP protocol can operate completely in a physically unidirectional isolated environment without any modification, improving data transmission reliability from UDP's "best-effort" to TCP-like reliable delivery.

[0018] Compared with existing solutions that use dual optical shutters but rely on self-developed ARQ protocol stacks, this invention does not reimplement the transport layer protocol, but only completes the binding of the transmit and receive channels on the periphery of the KCP protocol stack. Therefore, it can directly reuse mature KCP implementations and interoperate with standard KCP protocols, significantly reducing development and verification costs and maintenance complexity.

[0019] The server automatically sets the target address of the first UDP sender based on the source address of the first data packet, eliminating the need for static configuration of the reverse return address. This allows for automatic establishment of a return path even in scenarios where the client dynamically allocates IP addresses or uses NAT forwarding. Once the address learning state α is set to 1, it is irreversible; subsequent packets only allow data with the same learned address. This ensures the return address remains stable and is not tampered with by abnormal packets, while also increasing the ability to filter the source address of illegal packets. The first data packet carries both the source address and the KCP session identifier. The server can complete address learning and session establishment with a single parsing, eliminating the need for out-of-band handshakes or additional negotiation links.

[0020] The server automatically creates or reuses KCP protocol stack instances using the conv key in the packet payload. Session establishment is entirely driven by business data, eliminating the need for pre-registration or maintenance of additional session control state. Multiple session instances share the same first UDP sending endpoint, and all return data uses the same port and destination address. Port resource consumption does not increase with the number of sessions, effectively overcoming port resource bottlenecks in large-scale concurrent scenarios.

[0021] External applications only need to use standard send / receive interfaces, without needing to be aware of the physical separation of the forward and reverse links, to obtain end-to-end semantics consistent with TCP. This invention provides a reliable transmission service comparable to TCP for data export from high-security networks to low-security networks while maintaining a physically isolated unidirectional security boundary. Detailed Implementation

[0022] To clearly illustrate the technical features of this solution, the following detailed implementation method will be used to describe the solution.

[0023] Example 1: Server Initialization and Address Learning In this embodiment, the server is deployed on the internal network (low security level) side, and the client is deployed on the external network (high security level) side. The two are connected by a forward unidirectional optical shutter and a reverse unidirectional optical shutter to form a physically isolated environment.

[0024] The network configuration is as follows: The server read endpoint R is bound to the IP address 192.168.2.10:8080 of the forward optical gate output interface; the server write endpoint W is bound to the reverse optical gate input interface, and no remote target address is initially set; the client IP address is 192.168.1.50 (dynamically assigned via DHCP); the client UDP receive port is 9090, bound to the reverse optical gate output.

[0025] When the server starts, it reads the configuration to obtain the read address, creates UDP socket A as the read endpoint R and binds it to 192.168.2.10:8080; it creates UDP socket B as the write endpoint W, without specifying a remote target address. It initializes the address learning state α=0, the address storage area τ is empty, the session mapping table M is empty, and then starts the receive loop thread.

[0026] After startup, the client obtains a dynamic IP address (192.168.1.50) via DHCP and binds it to UDP receive port 9090. The client creates a KCP session (conv is 0x12345678) and sends its first data packet to the server address 192.168.2.10:8080. This data packet is a KCP protocol data segment, and the UDP header contains the source address 192.168.1.50:9090.

[0027] After receiving the data packet, the server-side read endpoint R obtains the source address A(p) = 192.168.1.50:9090 through the recvfrom system call. Since α = 0, the server performs first packet learning: assigning τ the value "192.168.1.50:9090", setting α to 1, and setting the remote target address of the write endpoint W to 192.168.1.50:9090.

[0028] The data packet then enters the session routing. In a preferred embodiment of the present invention, the session identifier is fixed in the first 4 bytes of the KCP protocol data packet payload, and is parsed into a 32-bit unsigned integer according to network byte order. Specifically, let the data packet payload be a byte sequence B, containing n bytes from b0, b1, b2, b3 to bn-1, where n≥4, then the session identifier conv=(b0<<24)|(b1<<16)|(b2<<8)|b3. In this embodiment, the conv of the data packet is 0x12345678.

[0029] The session mapping table M is queried using `conv` as the key. M is a mapping from 32-bit unsigned integers to KCP protocol stack instances. If `conv` does not have a corresponding entry in M, a new session is created, and the server executes the following creation process: Create a new KCP protocol stack instance k, call the standard ikcp_create function and pass in the conv value, initialize the KCP core data structure, and initialize the instance's send queue, receive queue, sliding window state and retransmission timer, all set according to the standard KCP protocol values.

[0030] Bind the output callback function `output` of node `k` to the first UDP sending endpoint `W`, so that all output data from `k` is sent to the learned target address `τ` through `W`. Specifically, the binding method is as follows: Set the `output` callback function of `k`, which takes a buffer pointer `buf`, a data length `len`, and a KCP instance pointer `kcp` as parameters. Within the function body, call the `sendto` method of `W` to send `len` bytes of data from `buf` to the target address `τ`.

[0031] Assign the mapping relationship M[conv] to k, and put the new instance k into the receiving queue so that the upper layer application can obtain data through recv or a similar interface.

[0032] If a corresponding entry for conv exists in M, then it is an existing session, and k can be directly obtained as M[conv] without needing to create it again.

[0033] Finally, the current data packet is input into the KCP protocol stack instance k, and the input method of k, i.e., the standard ikcp_input function, is called for processing. The KCP protocol stack parses this data packet: if it is a data packet, it is placed in the receive window and reassembled in order; if it is an ACK acknowledgment packet, the send window state is updated and the corresponding retransmission timer is cleared.

[0034] In a preferred embodiment, the receive buffer of the KCP protocol stack instance k adopts a circular buffer data structure. The buffer capacity is N (initially 4096 bytes, expandable as needed), the head pointer h points to the next data position to be read, and the tail pointer t points to the next data position to be written. The effective data length L = (t - h + N) mod N; the buffer is full when (t + 1) mod N = h; the buffer is empty when t = h. When the buffer is full and a new element needs to be written, expansion is triggered. The expansion strategy is: if N < 1MB, the capacity doubles; if N ≥ 1MB, it increases by 1MB each time. After expansion, the L effective elements in the original buffer are copied to the starting position of the new buffer in order from the head pointer to the logical tail, and then h = 0 and t = L are reset. Compared with linked list structures, this circular buffer structure has contiguous memory, high cache hit rate, and no pointer overhead, making it suitable for high-frequency data read / write network transmission scenarios.

[0035] After this, all data packets sent by the client are processed normally if the source address matches "192.168.1.50:9090", otherwise they are silently discarded. This mechanism ensures that even if an attacker forges data packets and sends them to the server, the packets will be discarded because the source address does not match, thus guaranteeing system security.

[0036] In this embodiment, the server does not perform any out-of-band handshake negotiation independent of the KCP data payload, nor does it pre-configure the remote target address of the write endpoint. The first KCP data segment carries both source address information and the conv field, completing address learning and session establishment in one step.

[0037] Example 2: Reliable Transmission Closed Loop This embodiment follows Embodiment 1, describing the complete closed-loop process of reliable transmission between the client and the server after the session is established.

[0038] Phase 1: Data Submission and Sharding Suppose that the data submitted by the upper-layer application calling the KCP send interface (such as the ikcp_send function) is a byte sequence D. The KCP protocol stack divides it into m segments, denoted as S0, S1, up to S(m-1), according to the current sending window and MSS. Each segment Si contains: a sequence number sn_i, a monotonically increasing integer assigned by the KCP protocol stack, satisfying that sn_i equals sn_0 plus i, and the initial sequence number sn_0 is randomly generated when the session is established; a payload_i, which is a data fragment not exceeding the MSS; and a KCP protocol header, containing information such as the session identifier conv, sequence number, and flag bits.

[0039] Phase 2: Sending and ACK Confirmation The client sends segment Si via its second UDP send endpoint through a forward unidirectional optical gate. The server receives the segment via its read endpoint R, performs address filtering and session routing, and then inputs the corresponding KCP protocol stack instance k.

[0040] Upon receiving a segment, k performs the following operations: Verifies the segment's validity; if sn_i is within the receive window (i.e., sn_i is greater than or equal to rcv_nxt and less than rcv_nxt plus rcv_wnd), the data is placed in the receive buffer and sorted by sequence number; an acknowledgment packet ACK(sn_i) is generated, with sn_i inserted into the KCP acknowledgment header, and sent via k's output callback. Since the output callback is bound to the write endpoint W, this ACK packet is sent to the client's target address τ via the reverse unidirectional optical gate; if an out-of-order segment is received (i.e., sn_i is greater than rcv_nxt), an ACK packet carrying selective acknowledgment information is generated to inform the sender of received and unreceived segments.

[0041] After receiving the ACK packet through its UDP receiving endpoint, the client routes it to the corresponding KCP protocol stack instance according to the session identifier, updates the sending window state, and marks the corresponding segment as acknowledged. The acknowledgment function Confirm(t,sn) is defined as follows: if an ACK acknowledgment for sequence number sn has been received before time t, Confirm(t,sn) equals 1; otherwise, it equals 0.

[0042] Phase 3: Timeout Retransmission The client-side KCP protocol stack checks all sent but unacknowledged segments during each `ikcp_update` call. Let the sending time of segment Si be `t0`, the current time be `t_now`, and the retransmission timeout for this segment be `RTO_i`. If both `t_now - t0` and `RTO_i` are greater than `RTO_i` and `Confirm(t_now, sn_i)` equal to 0, then a retransmission is triggered, Si is added back to the transmission queue, and retransmitted via the forward unidirectional optical gate.

[0043] The timeout RTO_i' after retransmission is updated according to the KCP standard backoff algorithm to RTO_i multiplied by (1+β), where β is the backoff factor, ranging from 0.5 to 1.0. The specific value is dynamically calculated by the congestion control module of the KCP protocol stack based on the packet loss rate. The backoff mechanism avoids the exacerbation of network congestion caused by invalid retransmissions during continuous packet loss.

[0044] Phase 4: Data Delivery When the server-side KCP protocol stack confirms that the segments corresponding to sn_0, sn_1 up to sn_i have arrived in order, that is, the segment sequence in the receiving window is continuous, it will combine payload_0 to payload_i in order and put them into the read buffer for the upper layer application to read through the ikcp_recv interface.

[0045] The differences between this embodiment and the standard KCP protocol are as follows: the fragmentation mechanism, retransmission triggering and backoff algorithm, and in-order delivery mechanism in phases 1, 3, and 4 are all standard mechanisms of the KCP protocol, and this invention has not made any modifications to them. The core difference between this embodiment and the standard KCP protocol lies only in the send / receive path in phase 2:

[0046] In the standard KCP protocol, data transmission and acknowledgment reception use the same UDP socket, and the round-trip path of data packets is symmetrical. In this invention, the transmission uses the write endpoint W and the reception uses the read endpoint R. The two endpoints are physically independent. The outbound path goes through the forward unidirectional optical gate and the return path goes through the reverse unidirectional optical gate. The round-trip path is asymmetrical, but they are merged into a logical bidirectional session within the KCP protocol stack.

[0047] Assuming the forward link packet loss rate is p_f and the reverse link packet loss rate is p_r, the probability that a segment is successfully received by the server and successfully ACKed back is (1-p_f)×(1-p_r). If packet loss occurs, KCP's timeout retransmission mechanism continuously retransmits according to the RTO backoff algorithm until the segment is acknowledged or the session is closed. KCP has a retransmission limit (KCP_DEADLINK, default 20 times). Retransmission continues throughout the session's lifetime. Within the KCP retransmission limit and session lifetime, if either the forward or reverse link becomes available again, unacknowledged segments will be finally acknowledged through timeout retransmission or fast retransmission. If the retransmission / session limit is continuously exceeded, the session is closed according to KCP's existing Deadlink mechanism, and an error is reported to the upper layer. This mechanism is consistent with TCP's retransmission guarantee principle in bidirectional networks, maintaining end-to-end reliability even when packet loss occurs on both unidirectional links.

[0048] Example 3: Multi-session shared write endpoint This embodiment describes the processing procedure under multiple concurrent session scenarios, and specifically illustrates the working method of multiple instances of the server sharing the write endpoint.

[0049] Multiple applications run simultaneously within the client, each establishing an independent KCP session. For clarity, let's take two applications as an example: App A uses conv=0x11111111, and App B uses conv=0x22222222. Both sessions share the same client IP address and port 192.168.1.50:9090, and receive acknowledgment packets from the server through the same UDP receive socket. A session distribution module is set up on the client side; upon receiving an acknowledgment packet, it distributes the packet to the corresponding KCP protocol stack instance based on the conv field.

[0050] After receiving the first data packet with conv=0x11111111, the server completes address learning, and the target address for the write endpoint W is fixed at 192.168.1.50:9090. Subsequently, when it receives a data packet with conv=0x22222222, the packet is allowed to pass because its source address matches the learned address. The session routing module queries the mapping table M based on the conv value, routing 0x11111111 to instance k0 and 0x22222222 to instance k1.

[0051] Both instances' output callback functions are bound to the write endpoint W and share the same destination address. When instance k0 needs to send an ACK, it sends it to 192.168.1.50:9090 via the write endpoint W; instance k1 sends it to the same address. After the client receives the acknowledgment packet, the session distribution module distributes the acknowledgment packet to the corresponding application session based on the conv value. The two sessions share the same UDP port but do not cause crosstalk.

[0052] Generalizing to the general case, suppose there are n active sessions, denoted as K0, K1, up to K(n-1), all sharing the same write endpoint W. For any session Ki, its output callback function output_i captures the socket handle of W and the learned target address τ. When Ki needs to send a data packet p (including data segments, ACK packets, window probe packets, etc.), it executes output_i(p) = W.sendto(p, τ), meaning that all sessions' output data is sent through the same UDP socket W to the same target address τ, which is the client's receiving address. Since all sessions share the same target address τ, sharing the write endpoint will not cause target address conflicts. After receiving the data packet, the client extracts the Conv field from the data packet and distributes the data packet to the corresponding local session instance.

[0053] The concurrency safety of the shared write endpoint model described above is guaranteed by the following properties: First, there is no state contention. The sendto operation for writing to the endpoint is a system call. The operating system's UDP protocol stack ensures that when multiple threads call sendto simultaneously, each data packet is correctly serialized and sent as an independent datagram at the underlying level, and the data packet content will not be overwritten.

[0054] Second, there is no shared state. The KCP protocol stack states of each session are independent of each other, and they do not share variable states such as send queue, receive window, retransmission timer, and congestion control parameters. Therefore, there is no lock contention problem.

[0055] Third, the target address is fixed. All sessions share the same target address, eliminating the need for dynamic switching of target addresses and further reducing the complexity of concurrent implementation.

[0056] Therefore, no matter how many concurrent sessions the server supports, it only needs one read endpoint and one write endpoint. The port resource consumption is reduced from linearly increasing with the number of sessions in the traditional solution to a fixed value, and the port resource bottleneck in large-scale concurrent scenarios is eliminated.

[0057] Example 4: System Architecture Comparison This embodiment compares the present invention with the typical "front-end server plus back-end server" deployment mode in the prior art.

[0058] The comparison conditions are as follows: the network environment is the same, both use forward unidirectional optical gates and reverse unidirectional optical gates to achieve physical isolation; and the number of concurrent sessions carried is the same.

[0059] The existing "front-end plus back-end" solution involves four logical network elements: a front-end unit, a back-end unit, a forward unidirectional optical gate, and a reverse unidirectional optical gate. The front-end unit provides TCP access to the client, and the back-end unit provides TCP access to the server. The front-end and back-end units communicate via two independent UDP channels, one for forward data and the other for reverse acknowledgment data. The TCP connection between the client and server is thus truncated into two segments: the client-to-front-end unit segment and the back-end unit-to-server segment, with an unreliable UDP pass-through segment in between. In this solution, each session requires two UDP ports and two TCP ports, and port resource consumption increases linearly with the number of concurrent sessions. The system involves four network elements and five communication links, each requiring independent configuration, monitoring, and troubleshooting; deployment and debugging cycles are typically measured in hours.

[0060] This invention involves only two logical network elements: a client and a server. The client connects to the forward and reverse optical gates respectively via a UDP send endpoint and a UDP receive endpoint; the server connects to the output of the forward optical gate and the input of the reverse optical gate respectively via a UDP read endpoint and a UDP write endpoint. All concurrent sessions share the two ports of the client and the two ports of the server, and port resource usage does not increase with the number of sessions. An end-to-end KCP logical bidirectional session is established between the client and the server, without any intermediate forwarding nodes. The logical communication link is simplified from the multi-segment forwarding of traditional solutions to a single end-to-end reliable link.

[0061] Taking 1000 concurrent sessions as an example, traditional solutions require approximately 4000 port resources (2 UDP ports and 2 TCP ports per session), while the solution of this invention only requires 4 UDP ports, reducing port resource consumption by more than 99%. In terms of the number of network elements, this invention simplifies the traditional solution from 4 network elements to 2, reducing system complexity by more than 50%. Regarding deployment and debugging, traditional solutions require configuring IP addresses, routing, port mapping, and forwarding rules on four devices and verifying the connectivity of five links one by one, typically taking several hours. This invention only requires configuring the KCP endpoint parameters on the client and server sides; the server does not need to know the client address in advance, reducing deployment time to several minutes. At the operation and maintenance level, because there are no intermediate forwarding nodes, the fault location scope of this invention is narrowed from five links to both ends and two optical gateway physical lines, significantly reducing daily monitoring and troubleshooting costs.

[0062] The above comparison shows that, while maintaining the physical unidirectional isolation capability, the present invention achieves reliable end-to-end data transmission with fewer network elements, lower port consumption, and a simpler deployment process, and the overall system operation and maintenance complexity is significantly reduced compared with existing solutions.

[0063] Of course, the above description is not limited to the examples above. Technical features not described in this invention can be implemented by or using existing technology, and will not be repeated here. The above embodiments are only used to illustrate the technical solutions of this invention and are not intended to limit this invention. This invention has been described in detail with reference to preferred embodiments. Those skilled in the art should understand that any changes, modifications, additions or substitutions made by those skilled in the art within the scope of this invention do not depart from the spirit of this invention and should also fall within the scope of protection of the claims of this invention.

Claims

1. A one-way transmission communication method based on KCP protocol, applied to a physically isolated network environment comprising a forward one-way transmission device and a reverse one-way transmission device, characterized in that: include: The server creates the first UDP receive endpoint and the first UDP send endpoint; The first UDP receiving endpoint is connected to the output of the forward unidirectional transmission device and is used to receive data packets sent by the client; The first UDP sending endpoint does not specify a destination address in its initial state and is connected to the input of the reverse one-way transmission device to send data packets to the client; The server receives the first data packet from the client through the first UDP receiving endpoint, obtains the source network address of the first data packet, and sets the destination address of the first UDP sending endpoint to the source network address; The server inputs the data packets from the first UDP receiving endpoint into the KCP protocol stack instance for processing, and binds the output callback of the KCP protocol stack instance to the first UDP sending endpoint, so that the acknowledgment packets and retransmission packets generated by the KCP protocol stack instance are sent to the set source network address through the first UDP sending endpoint; The input of the KCP protocol stack instance comes only from the first UDP receiving endpoint, and the output is sent only through the first UDP sending endpoint. A logical bidirectional session is formed within the KCP protocol stack instance. On the physical link, the forward unidirectional transmission device carries the data packet transmission, and the reverse unidirectional transmission device carries the acknowledgment packet and retransmission packet transmission.

2. The KCP protocol based one-way transmission communication method according to claim 1, characterized in that: The server also maintains the address learning state α and the address storage area τ; When the first data packet is received when α=0, the following steps are executed: assign τ the source network address of the first data packet, set α to 1, and set the destination address of the first UDP sending endpoint to the source network address; When α=1, the server obtains the source network address of subsequent data packets. If the source network address is different from τ, the data packet is discarded. The transition of α from 0 to 1 is irreversible, and the target address of the first UDP sending endpoint remains unchanged after α is set to 1.

3. The method according to claim 1, wherein the KCP protocol based one-way transmission communication method is characterized in that: The server parses the KCP session identifier conv from the first 4 bytes of the data packet payload in network byte order; Query the session mapping table M using conv as the key; If no corresponding entry exists in M, a KCP protocol stack instance is created, the output callback function of the instance is bound to the first UDP sending endpoint, and the mapping relationship between conv and the KCP protocol stack instance is stored in M; If a corresponding entry already exists in M, then obtain the already created KCP protocol stack instance; The current data packet is input into the obtained KCP protocol stack instance for processing.

4. The KCP protocol based one-way transmission communication method according to claim 1, characterized in that: When multiple KCP protocol stack instances exist on the server side, the output callback functions of each KCP protocol stack instance are all bound to the same first UDP sending endpoint and share the same target address; the server only occupies one first UDP receiving port and one first UDP sending port for multiple concurrent KCP sessions.

5. The one-way transmission communication method based on the KCP protocol according to claim 1, characterized in that: The KCP protocol stack instance adopts the standard KCP protocol's send queue, receive queue, sliding window state, and retransmission timer without modifying the core KCP protocol algorithm. By setting up an address learning module and a channel separation module around the KCP protocol stack instance, the input channel of the KCP protocol stack instance is bound to the first UDP receive endpoint, and the output callback of the KCP protocol stack instance is bound to the first UDP send endpoint, thus achieving separation of the physical path for sending and receiving.

6. The one-way transmission communication method based on the KCP protocol according to claim 1, characterized in that: Before completing address learning through the first data packet, the server does not perform a handshake negotiation process independent of the KCP data payload, nor does it pre-configure the target address of the first UDP sending endpoint; the first data packet is a KCP protocol data segment, the payload of which contains the KCP session identifier conv; the server only completes the target address setting of the first UDP sending endpoint based on the source address of this KCP segment.

7. The one-way transmission communication method based on the KCP protocol according to claim 1, characterized in that: The client is the data sender, and the server is the data receiver. At least the following reliable transmission mechanisms must be maintained between the server's KCP protocol stack instance and the client's KCP protocol stack instance: ARQ Automatic Retransmission Request Mechanism: After the data sending side sends a segment, it starts a retransmission timer. If no corresponding ACK confirmation is received within the retransmission timeout period RTO, the segment is added back to the sending queue and retransmitted through the forward unidirectional transmission device. Timeout backoff mechanism: The timeout after retransmission is updated according to RTO×(1+β); Sliding window flow control mechanism and selective acknowledgment mechanism: The data receiving side carries acknowledgment information and selective acknowledgment information through ACK packets, and the data sending side only retransmits unacknowledged segments; In-order delivery mechanism: The data receiving side buffers and reorders out-of-order message segments, and delivers them to the upper-layer application in order after the messages are continuous.

8. The one-way transmission communication method based on the KCP protocol according to claim 1, characterized in that: The server provides standard send / recv read / write interfaces to upper-layer applications. The KCP protocol stack instance is responsible for data fragmentation, transmission, acknowledgment, and ordering, shielding the details of the separation of send and receive paths caused by forward and reverse unidirectional transmission devices, and presenting a reliable bidirectional interaction mode similar to TCP to the outside world.

9. A communication system using the one-way transmission communication method based on the KCP protocol according to any one of claims 1 to 9, applied in a physically isolated network environment including a forward one-way transmission device and a reverse one-way transmission device, characterized in that, include: The client is configured with a second UDP sending endpoint and a second UDP receiving endpoint; The second UDP sending endpoint is connected to the input of the forward unidirectional transmission device and is used to send KCP data packets to the server. The second UDP receiving endpoint is connected to the output of the reverse one-way transmission device and is used to receive KCP acknowledgment packets and retransmission packets from the server. The server is configured with a first UDP receiving endpoint, a first UDP sending endpoint, an address learning module, and a KCP protocol stack instance. The first UDP receiving endpoint is connected to the output of the forward unidirectional transmission device and is used to receive KCP data packets from the client. The first UDP sending endpoint is connected to the input of the reverse unidirectional transmission device. Initially, no destination address is specified, and it is used to send KCP acknowledgment packets and retransmission packets to the client. The address learning module is connected to the first UDP receiving endpoint and the first UDP sending endpoint respectively. It is used to set the target address of the first UDP sending endpoint according to the source network address of the first KCP data packet received by the first UDP receiving endpoint, so that a reverse feedback link is formed between the first UDP sending endpoint and the second UDP receiving endpoint via the reverse unidirectional transmission device. The input channel of the KCP protocol stack instance is connected to the first UDP receiving endpoint, and the output callback is connected to the first UDP sending endpoint. This ensures that the data input of the KCP protocol stack instance comes only from the first UDP receiving endpoint, and the output is sent only through the first UDP sending endpoint. This forms a logical bidirectional session within the KCP protocol stack. On the physical network, the forward unidirectional transmission device carries the unidirectional transmission of data packets, and the reverse unidirectional transmission device carries the unidirectional transmission of acknowledgment packets and retransmission packets.

10. The communication system according to claim 9, characterized in that: The address learning module also maintains the address learning state α and the address storage area τ. When α=0, in response to the first UDP receiving endpoint receiving the first KCP packet, τ is assigned the source network address of the KCP packet, α is set to 1, and the destination address of the first UDP sending endpoint is set to τ. When α=1, if the source network address of subsequent KCP packets is different from τ, they are discarded. The server also includes a session management module, which is used to parse the KCP session identifier conv from the first 4 bytes of the KCP packet payload in network byte order, query the session mapping table M with conv as the key, and if there is no corresponding entry in M, create a KCP protocol stack instance and bind the output callback of the instance to the first UDP sending endpoint, and store the mapping relationship between conv and the instance in M. If there is already a corresponding entry in M, reuse the already created KCP protocol stack instance. When multiple KCP protocol stack instances exist on the server side, the output callbacks of each KCP protocol stack instance are bound to the same first UDP sending endpoint and share the same target address. The server only maintains one first UDP receiving port and one first UDP sending port for all concurrent KCP sessions.