Method and system for realizing local WEB interface without occupying ports based on IPC

By registering a custom protocol in the Electron app and using IPC communication, the problem of the inability to run stand-alone and complex page logic in the existing technology is solved, and the local WEB interface that does not occupy the port is realized, the standard http request function is supported, and the development is simplified. process.

CN119172371BActive Publication Date: 2025-02-18VISION MICROSYST (SHANGHAI) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411658528.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-20
Publication Date
2025-02-18
Estimated Expiration
2044-11-20

AI Technical Summary

Technical Problem

Existing applications developed based on Electron cannot run stand-alone when embedded web pages or injecting local APIs, and the page logic needs to be modified more. The work done through browser plug-ins is limited, so the request results cannot be directly customized.

Method used

By registering a standard custom protocol name when the Electron app is started, the page initiates interface requests through the custom protocol name. The Electron app intercepts the request and sends it to the local process through IPC. After parsing and processing, the response result is returned to achieve a local WEB that does not occupy the port. interface.

Benefits of technology

It realizes that page requests can be processed without occupying a port in the Electron app, and directly reuses the existing http request logic. The internal registration and interception protocol has no external side effects. It supports streaming, redirecting and other functions of standard http requests. It is the front-end and back-end core. Code can be reused to reduce development workload.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119172371B_ABST
    Figure CN119172371B_ABST
Patent Text Reader

Abstract

The present invention provides a method and system for realizing a local WEB interface without occupying a port based on IPC, including: registering a standard custom protocol name when the Electron app is started; the page initiates an interface request through the custom protocol name; the custom protocol request is intercepted in the Electron app, the request content is parsed, the request is converted into a message, and the message is sent to the local process through IPC (Inter-Process Communication); the local process receives the message passed in by the IPC channel, parses the message and matches the method to be executed according to the request header, and after execution, the return value is converted into a byte stream according to the standard HTTP response message format, and is transmitted back to the Electron app process through the IPC channel; the Electron app process obtains the response byte stream and parses it according to the standard HTTP response format, and transmits the parsed response result back to the page. The present invention is based on the local process responding to the request API interface in the Electron app, but does not occupy the local port, and achieves an effect similar to the http interface, ensuring that the page request has a similar processing logic to other http requests.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of browsers, and in particular to a method and system for realizing a local WEB interface without occupying a port based on IPC. Background Art

[0002] Currently, many applications developed based on electron basically embed a web page or call the local API through the injection method. The former cannot run on a single machine, and the page logic of the latter requires more modifications.

[0003] The patent document with the publication number CN116578802A discloses a government browser middleware adaptation system based on the Electron cross-platform technology. The original SDK of the peripheral manufacturer of the middleware is integrated in the device call C++ dynamic library packaged according to the preset unified standard. The device call C++ dynamic library packaged according to the preset unified standard and the HTTPAPI packaged according to the preset unified standard for the middleware are encapsulated through an interface; the device call C++ dynamic library packaged according to the preset unified standard of the middleware is output to the adaptation hardware dynamic library version of the preset operating system platform of the government browser according to the unified standard; the HTTPAPI packaged according to the preset unified standard for the government browser calls the adaptation hardware dynamic library version of the preset operating system platform through a plug-in. By adding plug-ins, what can be done through browser plug-ins is limited, and the request results cannot be directly customized.

[0004] Therefore, it is necessary to propose a new technical solution to improve the above technical problems. Summary of the invention

[0005] In view of the defects in the prior art, the object of the present invention is to provide a method and system for realizing a local WEB interface without occupying a port based on IPC.

[0006] According to a method for realizing a local WEB interface without occupying a port based on IPC provided by the present invention, the method comprises the following steps:

[0007] Step S1: Register the standard custom protocol name when the Electron app is started, call the method provided by Electron to register the custom protocol, pass in the protocol name and related configuration parameters, and register the protocol with the corresponding name in the Electron app context;

[0008] Step S2: the page initiates an interface request through the custom protocol name;

[0009] Step S3: The Electron app intercepts the custom protocol request, parses the request content, converts the request into a message, and sends it to the local process through IPC (Inter-Process Communication);

[0010] Step S4: The local process receives the message passed in by the IPC channel, parses the message and matches the method to be executed according to the request header. After execution, the return value is written into the byte array in the standard HTTP response message format, including the bytes of the response status code, blank lines, response header content bytes, blank lines, and response body bytes, and then transmitted back to the Electron app process through the IPC channel;

[0011] Step S5: The Electron app process obtains the response byte stream, parses it according to the standard HTTP response format, and transmits the parsed response result back to the page.

[0012] Preferably, parsing the request content and converting the request into a message in step S3 comprises the following steps:

[0013] Step S3.1: intercept the custom protocol request and suspend the current request;

[0014] Step S3.2: Parse the request header and request body;

[0015] Step S3.3: Convert the parsed content into a byte stream according to the standard HTTP message format.

[0016] Preferably, after the local process in step S4 receives the message transmitted by the IPC channel, the following steps are further included:

[0017] Step S4.1: Parse the message according to the standard HTTP format;

[0018] Step S4.2: Match the method to be executed according to the request header;

[0019] Step S4.3: Pass the request parameters and request body to the corresponding method, and obtain the return value after execution.

[0020] Preferably, the Electron app process in step S5 obtains the response byte stream and parses it according to the standard HTTP response format, including the following steps:

[0021] Step S5.1: Parse the response byte stream according to the standard HTTP response format;

[0022] Step S5.2: Use the parsed HTTP response as the request response result.

[0023] The present invention also provides a system for realizing a local WEB interface that does not occupy a port based on IPC, and the system applies the method for realizing a local WEB interface that does not occupy a port based on IPC, including:

[0024] Custom protocol registration module: used to register standard custom protocol names when the Electron app starts;

[0025] Request initiation module: used for the page to initiate an interface request through the custom protocol name;

[0026] Request interception and conversion module: used to intercept the custom protocol request, parse the request content, convert the request into a message, and send it to the local process through IPC;

[0027] Message processing and response module: used by the local process to receive messages from the IPC channel, parse the messages and match the method to be executed according to the request header. After execution, the return value is converted into a byte stream according to the standard HTTP response message format and transmitted back to the Electron app process through the IPC channel;

[0028] Response parsing and return module: used by the Electron app process to obtain the response byte stream, parse it according to the standard HTTP response format, and pass the parsed response result back to the page.

[0029] Preferably, the request interception and conversion module includes:

[0030] Request suspension unit: used to suspend the current request after intercepting the custom protocol request;

[0031] Parsing unit: used to parse the request header and request body;

[0032] Message conversion unit: used to convert the parsed content into a byte stream according to the standard HTTP message format.

[0033] Preferably, the message processing and response module includes:

[0034] Message parsing unit: used to parse messages according to standard HTTP format;

[0035] Method matching unit: used to match the method to be executed according to the request header;

[0036] Execution and return unit: used to pass request parameters and request body to the corresponding method, obtain the return value after execution, and convert the return value into a byte stream according to the standard HTTP response message format.

[0037] Compared with the prior art, the present invention has the following beneficial effects:

[0038] 1. The present invention responds to the request API interface in the Electron app based on the local process, but does not occupy the local port, achieves an effect similar to the http interface, and ensures that the page request has a similar processing logic to other http requests;

[0039] 2. The present invention solves the problem of additional processing work for page data requests by registering a custom protocol in the electron app, and directly reuses the existing http request logic. At the same time, the protocol intercepted by the internal registration has no external side effects at all, and neither a new protocol is added nor ports are occupied;

[0040] 3. The present invention solves the problem of communication difficulties between the local process data interface and the page by communicating with the local process IPC, parsing and transmitting HTTP messages;

[0041] 4. The core codes of the front-end and back-end of the present invention can be reused in stand-alone operation and web deployment, which greatly reduces the development workload. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:

[0043] Figure 1 It is the overall flow chart of the present invention;

[0044] Figure 2 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION

[0045] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.

[0046] Embodiment 1:

[0047] Reference Figure 1 and Figure 2 According to a method for realizing a local WEB interface without occupying a port based on IPC provided by the present invention, the method comprises the following steps:

[0048] Step S1: Register the standard custom protocol name when the Electron app is started, call the method provided by Electron to register the custom protocol, pass in the protocol name and related configuration parameters, and register the protocol with the corresponding name in the Electron app context;

[0049] Step S2: the page initiates an interface request through the custom protocol name;

[0050] Step S3: The Electron app intercepts the custom protocol request, parses the request content, converts the request into a message, and sends it to the local process through IPC (Inter-Process Communication);

[0051] Parsing the request content and converting the request into a message includes the following steps:

[0052] Step S3.1: intercept the custom protocol request and suspend the current request;

[0053] Step S3.2: Parse the request header and request body;

[0054] Step S3.3: Convert the parsed content into a byte stream according to the standard HTTP message format.

[0055] Step S4: The local process receives the message passed in by the IPC channel, parses the message and matches the method to be executed according to the request header. After execution, the return value is written into the byte array in the standard HTTP response message format, including the bytes of the response status code, blank lines, response header content bytes, blank lines, and response body bytes, and then transmitted back to the Electron app process through the IPC channel;

[0056] After the local process receives the message from the IPC channel, it also includes the following steps:

[0057] Step S4.1: Parse the message according to the standard HTTP format;

[0058] Step S4.2: Match the method to be executed according to the request header;

[0059] Step S4.3: Pass the request parameters and request body to the corresponding method, and obtain the return value after execution.

[0060] Step S5: The Electron app process obtains the response byte stream, parses it according to the standard HTTP response format, and transmits the parsed response result back to the page.

[0061] After the Electron app process obtains the response byte stream, it parses it according to the standard HTTP response format, including the following steps:

[0062] Step S5.1: Parse the response byte stream according to the standard HTTP response format;

[0063] Step S5.2: Use the parsed HTTP response as the request response result.

[0064] The present invention also provides a system for realizing a local WEB interface that does not occupy a port based on IPC, and the system applies the method for realizing a local WEB interface that does not occupy a port based on IPC, including:

[0065] Custom protocol registration module: used to register standard custom protocol names when the Electron app starts;

[0066] Request initiation module: used for the page to initiate an interface request through the custom protocol name;

[0067] Request interception and conversion module: used to intercept the custom protocol request, parse the request content, convert the request into a message, and send it to the local process through IPC;

[0068] The request interception and conversion modules include:

[0069] Request suspension unit: used to suspend the current request after intercepting the custom protocol request;

[0070] Parsing unit: used to parse the request header and request body;

[0071] Message conversion unit: used to convert the parsed content into a byte stream according to the standard HTTP message format.

[0072] Message processing and response module: used by the local process to receive messages from the IPC channel, parse the messages and match the method to be executed according to the request header. After execution, the return value is converted into a byte stream according to the standard HTTP response message format and transmitted back to the Electron app process through the IPC channel;

[0073] The message processing and response modules include:

[0074] Message parsing unit: used to parse messages according to standard HTTP format;

[0075] Method matching unit: used to match the method to be executed according to the request header;

[0076] Execution and return unit: used to pass request parameters and request body to the corresponding method, obtain the return value after execution, and convert the return value into a byte stream according to the standard HTTP response message format.

[0077] Response parsing and return module: used by the Electron app process to obtain the response byte stream, parse it according to the standard HTTP response format, and pass the parsed response result back to the page.

[0078] Embodiment 2:

[0079] The present invention provides a method for realizing a local WEB interface without occupying a port based on IPC, comprising the following steps:

[0080] Step 1: Register the standard custom protocol name when the Electron app starts;

[0081] Step 2: The page initiates an interface request with a custom protocol name;

[0082] Step 3: The Electron app intercepts the protocol request, parses the request content and converts the request into a message and sends it to the local process via ipc. After waiting for the message sent back by the ipc of the local process, it parses the message and returns it to the page.

[0083] Wherein step 3 comprises the following steps:

[0084] Step 3.1: Intercept the custom protocol request, suspend the current request, parse the request header and request body, and convert the parsed content into a byte stream according to the standard http message format.

[0085] Step 3.2: Send the byte stream generated in step 3.1 to the local process through the ipc connection channel with the local process.

[0086] Step 3.3: The local process obtains the byte stream passed in by the ipc channel, parses it according to the standard http format, matches the method to be executed according to the request header, passes the request parameters and request body to the corresponding method, and obtains the return value.

[0087] Step 3.4: After the local process obtains the return value, it converts it into a byte stream according to the standard HTTP response message format and transmits it back to the electron app process through the IPC channel.

[0088] Step 3.5: After the electron app obtains the response byte stream, it parses it according to the standard HTTP response format and passes it back to the page as the request response result.

[0089] Through this method, the page can call local process methods without any sense, and support streaming, redirection and other functions of standard http requests.

[0090] Those skilled in the art may understand this embodiment as a more specific description of Embodiment 1.

[0091] Those skilled in the art know that, in addition to realizing the system and its various devices, modules, and units provided by the present invention in a purely computer-readable program code, it is entirely possible to realize the same functions in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, the system and its various devices, modules, and units provided by the present invention can be considered as a hardware component, and the devices, modules, and units included therein for realizing various functions can also be regarded as structures within the hardware component; the devices, modules, and units for realizing various functions can also be regarded as both software modules for realizing the method and structures within the hardware component.

[0092] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.

Claims

1. A method for realizing a local WEB interface without occupying a port based on IPC, characterized in that: The method comprises the following steps: Step S1: Register the standard custom protocol name when the Electron app is started, call the method provided by Electron to register the custom protocol, pass in the protocol name and related configuration parameters, and register the protocol with the corresponding name in the Electron app context; Step S2: the page initiates an interface request through the custom protocol name; Step S3: The Electron app intercepts the custom protocol request, parses the request content, converts the request into a message, and sends it to the local process through IPC (Inter-Process Communication); Step S4: The local process receives the message passed in by the IPC channel, parses the message and matches the method to be executed according to the request header. After execution, the return value is written into the byte array in the standard HTTP response message format, including the bytes of the response status code, blank lines, response header content bytes, blank lines, and response body bytes, and then transmitted back to the Electron app process through the IPC channel; Step S5: The Electron app process obtains the response byte stream, parses it according to the standard HTTP response format, and transmits the parsed response result back to the page; The parsing of the request content and converting the request into a message in step S3 includes the following steps: Step S3.1: intercept the custom protocol request and suspend the current request; Step S3.2: Parse the request header and request body; Step S3.3: convert the parsed content into a byte stream according to the standard HTTP message format; After the local process in step S4 receives the message transmitted by the IPC channel, the following steps are also included: Step S4.1: Parse the message according to the standard HTTP format; Step S4.2: Match the method to be executed according to the request header; Step S4.3: pass the request parameters and request body to the corresponding method, and obtain the return value after execution; The Electron app process in step S5 obtains the response byte stream and parses it according to the standard HTTP response format, including the following steps: Step S5.1: Parse the response byte stream according to the standard HTTP response format; Step S5.2: Use the parsed HTTP response as the request response result.

2. A system for realizing a local WEB interface without occupying a port based on IPC, characterized in that: The system application method for realizing a local WEB interface without occupying a port based on IPC as claimed in claim 1 comprises: Custom protocol registration module: used to register standard custom protocol names when the Electron app starts; Request initiation module: used for the page to initiate an interface request through the custom protocol name; Request interception and conversion module: used to intercept the custom protocol request, parse the request content, convert the request into a message, and send it to the local process through IPC; Message processing and response module: used by the local process to receive messages from the IPC channel, parse the messages and match the method to be executed according to the request header. After execution, the return value is converted into a byte stream according to the standard HTTP response message format and transmitted back to the Electron app process through the IPC channel; Response parsing and return module: used by the Electron app process to obtain the response byte stream, parse it according to the standard HTTP response format, and pass the parsed response result back to the page.

3. The system for realizing a local WEB interface without occupying a port based on IPC according to claim 2, characterized in that: The request interception and conversion module includes: Request suspension unit: used to suspend the current request after intercepting the custom protocol request; Parsing unit: used to parse the request header and request body; Message conversion unit: used to convert the parsed content into a byte stream according to the standard HTTP message format.

4. The system for realizing a local WEB interface without occupying a port based on IPC according to claim 2, characterized in that: The message processing and response module includes: Message parsing unit: used to parse messages according to standard HTTP format; Method matching unit: used to match the method to be executed according to the request header; Execution and return unit: used to pass request parameters and request body to the corresponding method, obtain the return value after execution, and convert the return value into a byte stream according to the standard HTTP response message format.

Citation Information

Patent Citations

  • Government affair browser middleware adaptation system based on Electron cross-platform technology

    CN116578802A