CN112995198A - Short-connection communication method and device based on socket - Google Patents

Short-connection communication method and device based on socket Download PDF

Info

Publication number
CN112995198A
CN112995198A CN202110333964.8A CN202110333964A CN112995198A CN 112995198 A CN112995198 A CN 112995198A CN 202110333964 A CN202110333964 A CN 202110333964A CN 112995198 A CN112995198 A CN 112995198A
Authority
CN
China
Prior art keywords
socket
target
event
target event
executing
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202110333964.8A
Other languages
Chinese (zh)
Other versions
CN112995198B (en
Inventor
孙瑞浩
石立宪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Citic Bank Corp Ltd
Original Assignee
China Citic Bank Corp Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Citic Bank Corp Ltd filed Critical China Citic Bank Corp Ltd
Priority to CN202110333964.8A priority Critical patent/CN112995198B/en
Publication of CN112995198A publication Critical patent/CN112995198A/en
Application granted granted Critical
Publication of CN112995198B publication Critical patent/CN112995198B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/161Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
    • H04L69/162Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Abstract

The invention relates to the technical field of communication, in particular to a short-connection communication method and device based on a socket. The method comprises the following steps: by initializing a system event mechanism; monitoring a server target interface and registering a target event based on socket; and executing the target process matched with the target event type according to the detected target event type. The scheme disclosed by the application occupies less system resources, does not need to manage the creation and recovery of processes or threads, and is better in robustness.

Description

Short-connection communication method and device based on socket
Technical Field
The invention relates to the technical field of communication, in particular to a short-connection communication method and device based on a socket.
Background
At present, high-concurrency socket synchronous short-connection communication mainly adopts a multithreading or multiprocessing mode. The multithreading mode is that a thread pool is established, and one thread is selected from the thread pool to realize high-concurrency communication when each communication request is sent; the multi-process mode is that each time a connection is established, a process needs to be established, and socket short connection communication is completed in a subprocess. However, the high-concurrency synchronous short-connection communication method realized by the current multi-process or multi-thread mode occupies more system resources, and needs to continuously perform process or thread management, so that the development complexity is higher.
Disclosure of Invention
The present application aims to solve at least one of the above technical drawbacks. The technical scheme adopted by the application is as follows:
in a first aspect, an embodiment of the present application discloses a short connection communication method based on a socket, which is applied to a server, and the method includes:
initializing a system event mechanism;
monitoring a server target interface and registering a target event based on socket;
and executing the target process matched with the target event type according to the detected target event type.
Optionally, registering the socket-based target event includes at least one of:
register snoop events, register queue events, register signal events.
Optionally, according to the detected target event type, executing the target process matched with the target event type includes:
and when the target event is detected to be a connection event, executing a process of creating a socket, registering the socket event and connecting the socket event with the client.
Optionally, the executing the target process matched with the target event type according to the detected target event type further includes:
when the target event is detected to be a socket reading event, executing a target process based on the socket, wherein the target process is used for receiving a request message sent by a client based on a target socket interface and generating a response message; wherein the request message and the response message have the same ID identification; or the like, or, alternatively,
and when the target event is detected to be a socket write event, executing a target process based on the socket, wherein the target process is used for disconnecting the communication connection based on the socket.
Optionally, when the detected socket-based read event is a communication message queue read event, the generated response message is sent to the client through the target socket interface.
Optionally, the executing, according to the detected target event type, the target process matched with the target event type includes:
when the target event is detected to be a stop progress signal event, the target progress based on the socket is stopped.
In a second aspect, an embodiment of the present application provides a short connection communication method based on a socket, which is applied to a client, and the method includes:
initializing a system event mechanism;
registering a target event based on the target socket; the target socket is used for sending a request message generated according to a user operation command or receiving a response message sent by a server; the response message is generated by the server according to the request message; the request message and the response message have the same ID identification;
and executing the target process matched with the target event type according to the detected target event type.
Optionally, the executing, according to the detected target event type, the target process matched with the target event type includes:
when the target event is detected to be a socket-based read event, the read event is a communication message queue read event, executing a process of creating a socket registration socket event and connecting a server;
and further, sending the request message to a server based on the created socket connection.
Optionally, the executing, according to the detected target event type, the target process matched with the target event type includes:
and when detecting that the target event is a socket reading event, executing a socket-based target process, wherein the target process is used for receiving a response message sent by the server and feeding back the response message to the user.
In a third aspect, an embodiment of the present application provides a short connection communication apparatus based on a socket, which is applied to a server, and the apparatus includes:
the device comprises an initialization module, a monitoring module, a registration module, a detection module and an execution module; wherein the content of the first and second substances,
the initialization module is used for initializing a system event mechanism;
the registration module is used for registering a target event based on a target socket; the target socket is used for sending a request message generated according to a user operation command or receiving a response message sent by a server; the response message is generated by the server according to the request message; the request message and the response message have the same ID identification;
the monitoring module is used for monitoring a target interface of the server;
the detection module is used for detecting a target event;
and the execution module is used for executing the target process matched with the target event type according to the detected target event type.
In a fourth aspect, an embodiment of the present application provides an electronic device, including a processor and a memory;
the memory is used for storing operation instructions;
the processor is configured to execute the method in any of the embodiments by calling the operation instruction.
In a fifth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the computer program implements the method of any one of the above embodiments.
The embodiment of the application provides a short-connection communication scheme based on socket, and a system event mechanism is initialized; monitoring a server target interface and registering a target event based on socket; and executing the target process matched with the target event type according to the detected target event type. The beneficial effects of the method at least comprise one of the following steps:
(1) compared with a multi-process or multi-thread mode, the communication scheme disclosed by the embodiment of the application occupies less system resources;
(2) compared with a multi-process or multi-thread mode, the communication scheme disclosed by the embodiment of the application does not need to manage the creation and recovery of processes or threads, does not have other hidden problems caused by improper multi-process or multi-thread management, and is better in robustness.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings used in the description of the embodiments of the present application will be briefly described below.
Fig. 1 is a schematic flowchart of a short-connection communication method based on a socket according to an embodiment of the present application;
fig. 2 is a schematic flowchart of a short-connection communication method based on a socket according to an embodiment of the present application;
fig. 3 is a schematic diagram of a short-connection communication device based on socket according to an embodiment of the present application
Fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
Reference will now be made in detail to embodiments of the present application, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the drawings are exemplary only for the purpose of explaining the present application and are not to be construed as limiting the present invention.
It will be understood by those skilled in the art that, unless otherwise specified, the singular forms "a", "an", "the" and "the" may include the plural forms, and the plural forms "a", "an", "a", and "the" are merely intended to illustrate the object definition for clarity and do not limit the object itself, and certainly, the object definition for "a" and "an" may be the same terminal, device, user, etc., and may also be the same terminal, device, user, etc. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof. As used herein, the term "and/or" includes all or any element and all combinations of one or more of the associated listed items.
In addition, it is to be understood that "at least one" in the embodiments of the present application means one or more, "a plurality" means two or more. "and/or" describes the association relationship of the associated objects, meaning that there may be three relationships, e.g., a and/or B, which may mean: a alone, both A and B, and B alone, where A, B may be singular or plural. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship. "at least one of the following" or similar expressions refer to any combination of these items, including any combination of the singular or plural items. For example, at least one (one) of a, b, or c, may represent: a, b, c, a and b, a and c, b and c, or a, b and c, wherein a, b and c can be single or multiple.
To more clearly describe the technical solution of the present application, the following describes some concepts, terms or devices that the following embodiments may relate to help understand the short connection communication scheme based on socket disclosed in the present application:
sockets are the foundation of communications and the basic unit of operation for a way communication that supports the TCP/IP protocol. Sockets can be viewed as endpoints for inter-process communication between different hosts, which constitutes a programmatic interface within a single host and across the entire network. Sockets exist in the communication domain, which is an abstraction introduced to handle general threads communicating through sockets. Sockets typically exchange data with sockets in the same domain (data exchange may also cross the domain boundaries, but some interpreter must be executed at this time), and various processes use this same domain to communicate with each other using an Internet protocol cluster. Socket can be regarded as an endpoint in the respective communication connection when two network applications communicate, which is a logical concept. It is an API (application programming interface) for interprocess communication in a network environment, and is also a communication endpoint that can be named and addressed, each socket in use having its type and a process connected to it. During communication, one network application program writes a piece of information to be transmitted into a Socket of a host where the network application program is located, and the Socket sends the piece of information into a Socket of another host through a transmission medium connected with a Network Interface Card (NIC) so that the other host can receive the piece of information. Socket is combined by IP address and port, providing a mechanism to deliver packets to application layer processes.
In this embodiment of the present application, the target event based on the Socket may be a Socket port event, and may also be an event that a downstream or upstream information stream is transmitted through a Socket port, for example, a message queue event for reading or transferring a message inside the system.
To make the objects, technical solutions and advantages of the present application more clear, embodiments of the present application will be described in further detail below with reference to the accompanying drawings.
The following describes the technical solutions of the present application and how to solve the above technical problems with specific embodiments. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments. Embodiments of the present application will be described below with reference to the accompanying drawings.
The following describes the technical solutions of the present application and how to solve the above technical problems with specific embodiments. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments. Embodiments of the present application will be described below with reference to the accompanying drawings.
Fig. 1 shows a schematic flowchart of short-connection communication based on a socket provided in an embodiment of the present application, and as shown in fig. 1, the method is applied to a server, and the method mainly includes:
s101, initializing a system event mechanism; namely, an operating system event initialization mechanism, the linux operating system event selectable mechanisms comprise epoll, poll and select, and the windows operating system event mechanism comprises IOCP.
S102, monitoring a target interface of a server and registering a target event based on a socket; wherein registering the socket-based target event comprises at least one of: register snoop events, register queue events, register signal events.
S103, executing a target process matched with the target event type according to the detected target event type. In the embodiment of the application, IO input and output events are circularly detected and the event types thereof are detected.
In an optional embodiment of the present application, executing, according to the detected target event type, a target process matching the target event type includes: and when the target event is detected to be a connection event, executing creating a socket and registering the socket event.
In an optional embodiment of the present application, the executing, according to the detected target event type, the target process matching the target event type further includes: when a target event is detected to be a socket read event, executing a target process based on a socket, wherein the target process is used for receiving a request message sent by a client based on a target socket interface, generating a unique ID, recording the corresponding relation between the socket and the unique ID, and then matching the target socket by using the unique ID; and triggering a read callback function to send the request message sent by the read client and the unique ID to other processes for processing.
In an optional embodiment of the present application, when the detected socket-based read event is a communication message queue read event, it indicates that a message to be responded by the user is received, and the response message is accompanied by a unique ID generated when the request message is received, and is used to match which message the response is. And searching a socket matched with the original request message by using the unique ID carried in the message, and if the socket is found, responding the message by the socket, namely sending the generated response message to the client through a target socket interface. If not, the socket is closed, and the response message is discarded.
In an optional embodiment of the present application, when it is detected that the target event is a socket write event, it indicates that the packet response has been completed, and a target process based on the socket is executed, where the target process is used to disconnect a communication connection based on the socket. And (5) the message response is completed and the connection is disconnected. In addition, when other events of the socket are detected, the socket processing is abnormal, and the communication connection between the server and the client is disconnected.
In an optional embodiment of the present application, the executing, according to the detected target event type, the target process matching the target event type includes: when the target event is detected to be a stop progress signal event, the target progress based on the socket is stopped.
Based on the short connection communication method based on socket shown in fig. 1, on the other hand, fig. 2 shows a schematic flow chart of short connection communication based on socket provided in the embodiment of the present application, as shown in fig. 2, the method is applied to a client, and the method mainly includes:
s201, initializing a system event mechanism;
s202, registering a target event based on a target socket; the target socket is used for sending a request message generated according to a user operation command or receiving a response message sent by a server; the response message is generated by the server according to the request message; the request message and the response message have the same ID identification; wherein registering the target event based on the target socket comprises: registering DNS resolution events, registering queue events (which are used to receive reply messages), registering signal events.
S203, according to the detected target event type (IO event occurring in the circular detection event pool), executing the target process matched with the target event type.
In the embodiment of the application, after receiving the response message of the server, the client process provides the received response message to the user through the callback interface, and the data provided to the user comprises the response message and the unique ID attached to the request message, so that the user can match the response of which message the response is.
In an optional embodiment of the present application, the executing, according to the detected target event type, the target process matching the target event type includes:
when the target event is detected to be a communication message queue reading event, the request message to be sent by the user is obtained, and the request message is attached with a unique ID for identifying the request message. Executing a process of creating a socket registration socket event and connecting a server; further, when other events except for socket reading and writing are detected, if the socket is connected with the event, the fact that the service end is connected is indicated, the request message is sent to the server through the created socket connection, the corresponding relation between the unique ID of the request message and the socket is recorded, and therefore the response message sent back by the server can find the ID to respond to the user; if the event is not a socket connected event, the socket processing exception is shown, and the connection is disconnected.
In an optional embodiment of the present application, the executing, according to the detected target event type, the target process matching the target event type includes:
and when detecting that the target event is a socket reading event, executing a socket-based target process, wherein the target process is used for receiving a response message sent by the server and feeding back the response message to the user.
All the embodiments shown in fig. 1 can be implemented in the embodiments of the present application, and are not described herein again.
In the embodiment of the present application, the server and the client are only used to introduce the technical solutions from the server side and the front-end operation side (client) respectively for clarity of the technical solutions, but the server side and the front-end operation side are in the same actual device carrier, and may of course be respectively carried in two actual device carriers, but the two actual device carriers may be the same type of device or different types of devices.
By adopting the communication scheme based on the socket, the programs of the client and the server run stably, and compared with the communication mode of a multi-process mode adopted by the system before, the system occupies fewer system resources and the concurrency capability is greatly improved.
Based on the short-connection communication method based on socket shown in fig. 1, in another aspect, an embodiment of the present application provides a short-connection communication apparatus based on socket, where the apparatus is applied to a server, and as shown in fig. 3, the apparatus may include: a 301 initialization module, a 302 listening module, a 303 registration module, a 304 detection module and a 305 execution module; wherein the content of the first and second substances,
the 301 initialization module is configured to initialize a system event mechanism;
the 303 registration module is used for registering a target event based on a target socket; the target socket is used for sending a request message generated according to a user operation command or receiving a response message sent by a server; the response message is generated by the server according to the request message; the request message and the response message have the same ID identification;
the 302 monitoring module is used for monitoring a target interface of a server;
the 304 detection module is used for detecting a target event;
the 305 executing module is configured to execute a target process matched with the target event type according to the detected target event type.
It is understood that the above-described respective constituent devices of the socket-based short-connection communication apparatus in the present embodiment have functions of implementing the respective steps of the method in the embodiment shown in fig. 1 and 2. The function can be realized by hardware, and can also be realized by executing corresponding software by hardware. The hardware or software includes one or more modules or systems corresponding to the above-described functions. The modules and systems can be software and/or hardware, and the modules and systems can be realized independently or integrated by a plurality of modules and systems. For the functional description of each module and system, reference may be specifically made to the corresponding description of the method in the embodiment shown in fig. 1, and therefore, the beneficial effects that can be achieved by the method may refer to the beneficial effects in the corresponding method provided above, which are not described again here.
It is to be understood that the illustrated structure of the embodiment of the present invention does not constitute a specific limitation to the specific structure of the short-connection communication apparatus based on socket. In other embodiments of the present application, a socket-based short-connection communicator may include more or fewer components than shown, or combine certain components, or split certain components, or a different arrangement of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
The embodiment of the application provides an electronic device, which comprises a processor and a memory;
a memory for storing operating instructions;
and the processor is used for executing the short connection communication method based on the socket provided by any embodiment of the application by calling the operation instruction.
As an example, fig. 4 shows a schematic structural diagram of an electronic device to which the embodiment of the present application is applicable, and as shown in fig. 4, the electronic device 400 includes: a processor 401 and a memory 403. Wherein the processor 401 is coupled to the memory 403, such as via a bus 402. Optionally, the electronic device 400 may also include a transceiver 404. It should be noted that the transceiver 404 is not limited to one in practical applications. It is to be understood that the illustrated structure of the embodiment of the present invention does not constitute a specific limitation to the specific structure of the electronic device 400. In other embodiments of the present application, electronic device 400 may include more or fewer components than shown, or some components may be combined, some components may be split, or a different arrangement of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware. Optionally, the electronic device may further include a display screen 405 for displaying images or receiving operation instructions of a user as needed.
The processor 401 is applied to the embodiment of the present application, and is configured to implement the method shown in the foregoing method embodiment. The transceiver 404 may include a receiver and a transmitter, and the transceiver 404 is applied in the embodiment of the present application and is used for implementing the function of the electronic device of the embodiment of the present application to communicate with other devices when executed.
The Processor 401 may be a CPU (Central Processing Unit), a general purpose Processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other Programmable logic device, a transistor logic device, a hardware component, or any combination thereof. Which may implement or perform the various illustrative logical blocks, modules, and circuits described in connection with the disclosure. The processor 401 may also be a combination of computing functions, e.g., comprising one or more microprocessors, a combination of a DSP and a microprocessor, or the like.
Processor 401 may also include one or more processing units, such as: the processor 401 may include an Application Processor (AP), a modem processor, a Graphics Processing Unit (GPU), an Image Signal Processor (ISP), a controller, a memory, a video codec, a Digital Signal Processor (DSP), a baseband processor, and/or a Neural-Network Processing Unit (NPU), etc. The different processing units may be separate devices or may be integrated into one or more processors. The controller may be, among other things, a neural center and a command center of the electronic device 400. The controller can generate an operation control signal according to the instruction operation code and the timing signal to complete the control of instruction fetching and instruction execution. A memory may also be provided in processor 401 for storing instructions and data. In some embodiments, the memory in the processor 401 is a cache memory. The memory may hold instructions or data that have just been used or recycled by processor 401. If the processor 401 needs to reuse the instruction or data, it can be called directly from the memory. Avoiding repeated accesses reduces the latency of the processor 401, thereby increasing the efficiency of the system.
The processor 401 may operate the short connection communication method based on socket provided in the embodiment of the present application, so as to reduce the operation complexity of the user, improve the intelligent degree of the terminal device, and improve the experience of the user. The processor 401 may include different devices, for example, when the CPU and the GPU are integrated, the CPU and the GPU may cooperate to execute the socket-based short-connection communication method provided in the embodiment of the present application, for example, part of algorithms in the socket-based short-connection communication method are executed by the CPU, and another part of algorithms are executed by the GPU, so as to obtain faster processing efficiency.
Bus 402 may include a path that transfers information between the above components. The bus 402 may be a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus 402 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in FIG. 4, but this does not indicate only one bus or one type of bus.
The Memory 403 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact disk), a high speed Random Access Memory, a non-volatile Memory such as at least one magnetic disk storage device, a flash Memory device, a universal flash Memory (UFS), or other optical disk storage, optical disk storage (including Compact disk, laser disk, optical disk, digital versatile disk, blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage devices, a magnetic disk storage medium, or other types of magnetic storage devices, Or any other medium which can be used to carry or store desired program code in the form of instructions or data structures and which can be accessed by a computer, but is not limited to such.
Optionally, the memory 403 is used for storing application program codes for executing the scheme of the present application, and is controlled by the processor 401 to execute. The processor 401 is configured to execute the application program code stored in the memory 403 to implement the short-connection communication method based on socket provided in any embodiment of the present application.
The memory 403 may be used to store computer-executable program code, which includes instructions. The processor 401 executes various functional applications of the electronic device 400 and data processing by executing instructions stored in the memory 403. The memory 403 may include a program storage area and a data storage area. Wherein, the storage program area can store the codes of the operating system and the application program, etc. The stored data area may store data created during use of the electronic device 400 (e.g., images, video, etc. captured by a camera application), and the like.
The memory 403 may further store one or more computer programs corresponding to the short connection communication method based on socket provided in the embodiment of the present application. The one or more computer programs stored in the memory 403 and configured to be executed by the one or more processors 401 include instructions that may be used to perform the steps of the respective embodiments described above.
Of course, the code of the short-connection communication method based on socket provided in the embodiment of the present application may also be stored in the external memory. In this case, the processor 401 may execute the code of the socket-based short connection communication method stored in the external memory through the external memory interface, and the processor 401 may control the execution of the socket-based short connection communication flow.
The display screen 405 includes a display panel. The display panel may be a Liquid Crystal Display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (active-matrix organic light-emitting diode, AMOLED), a flexible light-emitting diode (FLED), a miniature, a Micro-oeld, a quantum dot light-emitting diode (QLED), or the like. In some embodiments, the electronic device 400 may include 1 or N display screens 405, N being a positive integer greater than 1. The display screen 405 may be used to display information input by or provided to the user as well as various Graphical User Interfaces (GUIs). For example, the display screen 405 may display a photograph, video, web page, or file, etc.
The electronic device provided by the embodiment of the present application is applicable to any embodiment of the above method, and therefore, the beneficial effects that can be achieved by the electronic device can refer to the beneficial effects in the corresponding method provided above, and are not described again here.
The embodiment of the application provides a computer-readable storage medium, which stores a computer program, and when the program is executed by a processor, the computer program implements the short-connection communication method based on socket shown in the above method embodiment.
The computer-readable storage medium provided in the embodiments of the present application is applicable to any embodiment of the foregoing method, and therefore, the beneficial effects that can be achieved by the computer-readable storage medium can refer to the beneficial effects in the corresponding method provided above, and are not described herein again.
The embodiment of the present application further provides a computer program product, which when running on a computer, causes the computer to execute the above related steps to implement the method in the above embodiment. The computer program product provided in the embodiments of the present application is applicable to any of the embodiments of the method described above, and therefore, the beneficial effects that can be achieved by the computer program product can refer to the beneficial effects in the corresponding method provided above, and are not described herein again.
The embodiment of the application provides a short-connection communication scheme based on socket, and a system event mechanism is initialized; monitoring a server target interface and registering a target event based on socket; and executing the target process matched with the target event type according to the detected target event type. Compared with a multi-process or multi-thread mode, the communication scheme disclosed by the embodiment of the application occupies less system resources, does not need to manage the creation and recovery of the processes or threads, does not have other implicit problems caused by improper multi-process or multi-thread management, and is better in robustness.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, a module or a unit may be divided into only one logical function, and may be implemented in other ways, for example, a plurality of units or components may be combined or integrated into another apparatus, or some features may be discarded or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
Units described as separate parts may or may not be physically separate, and parts displayed as units may be one physical unit or a plurality of physical units, may be located in one place, or may be distributed to a plurality of different places. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application may be essentially or partially contributed to by the prior art, or all or part of the technical solutions may be embodied in the form of a software product, where the software product is stored in a storage medium and includes several instructions to enable a device (which may be a single chip, a chip, or the like) or a processor (processor) to execute all or part of the steps of the methods of the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
It should be understood that, although the steps in the flowcharts of the figures are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and may be performed in other orders unless explicitly stated herein. Moreover, at least a portion of the steps in the flow chart of the figure may include multiple sub-steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed in sequence, but may be performed alternately or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of changes or substitutions within the technical scope of the present application, and can make several modifications and decorations, and these changes, substitutions, improvements and decorations should also be considered to be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (12)

1. A short connection communication method based on socket is applied to a server, and is characterized in that the method comprises the following steps:
initializing a system event mechanism;
monitoring a server target interface and registering a target event based on socket;
and executing the target process matched with the target event type according to the detected target event type.
2. The socket-based short connection communication method according to claim 1, wherein registering the socket-based target event comprises at least one of:
register snoop events, register queue events, register signal events.
3. The socket-based short-connection communication method according to claim 2, wherein executing a target process matching the target event type according to the detected target event type comprises:
and when the target event is detected to be a connection event, executing a process of creating a socket, registering the socket event and connecting the socket event with the client.
4. The socket-based short connection communication method according to claim 3, wherein executing the target process matching the target event type according to the detected target event type further comprises:
when the target event is detected to be a socket reading event, receiving a request message sent by a client based on a target socket interface and generating a response message; wherein the request message and the response message have the same ID identification; or the like, or, alternatively,
and when detecting that the target event is a socket write event, executing to disconnect the communication connection based on the socket.
5. The socket-based short connection communication method according to claim 4, wherein when the detected socket-based read event is a communication message queue read event, the generated response packet is sent to the client through a target socket interface.
6. The socket-based short connection communication method according to claim 5, wherein the executing the target process matching the target event type according to the detected target event type comprises:
when the target event is detected to be a stop progress signal event, the target progress based on the socket is stopped.
7. A short connection communication method based on socket is applied to a client side, and is characterized in that the method comprises the following steps:
initializing a system event mechanism;
registering a target event based on the target socket; the target socket is used for sending a request message generated according to a user operation command or receiving a response message sent by a server; the response message is generated by the server according to the request message; the request message and the response message have the same ID identification;
and executing the target process matched with the target event type according to the detected target event type.
8. The socket-based short connection communication method according to claim 7, wherein the executing the target process matching the target event type according to the detected target event type comprises:
when a target event based on a target socket is detected to be a queue read event of the communication message, executing a process of creating a socket registration socket event and connecting a server;
and further, sending the request message to a server based on the created socket connection.
9. The socket-based short-connection communication method according to claim 8, wherein the executing the target process matching the target event type according to the detected target event type comprises:
and when the target event is detected to be a socket reading event, executing to receive a response message sent by the server, and feeding back the response message to the user.
10. A socket-based short-connection communication device, the device comprising: the device comprises an initialization module, a monitoring module, a registration module, a detection module and an execution module; wherein the content of the first and second substances,
the initialization module is used for initializing a system event mechanism;
the registration module is used for registering a target event based on a target socket; the target socket is used for sending a request message generated according to a user operation command or receiving a response message sent by a server; the response message is generated by the server according to the request message; the request message and the response message have the same ID identification;
the monitoring module is used for monitoring a target interface of the server;
the detection module is used for detecting a target event;
and the execution module is used for executing the target process matched with the target event type according to the detected target event type.
11. An electronic device comprising a processor and a memory;
the memory is used for storing operation instructions;
the processor is used for executing the method of any one of claims 1-6 or 7-9 by calling the operation instruction.
12. A computer-readable storage medium, characterized in that the storage medium has stored thereon a computer program which, when being executed by a processor, carries out the method of any one of claims 1-6 or 7-9.
CN202110333964.8A 2021-03-29 2021-03-29 Short-connection communication method and device based on socket Active CN112995198B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110333964.8A CN112995198B (en) 2021-03-29 2021-03-29 Short-connection communication method and device based on socket

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110333964.8A CN112995198B (en) 2021-03-29 2021-03-29 Short-connection communication method and device based on socket

Publications (2)

Publication Number Publication Date
CN112995198A true CN112995198A (en) 2021-06-18
CN112995198B CN112995198B (en) 2023-04-28

Family

ID=76338855

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110333964.8A Active CN112995198B (en) 2021-03-29 2021-03-29 Short-connection communication method and device based on socket

Country Status (1)

Country Link
CN (1) CN112995198B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010029548A1 (en) * 2000-04-08 2001-10-11 Geetha Srikantan Method and apparatus for handling events received at a server socket
US7263550B1 (en) * 2000-10-10 2007-08-28 Juniper Networks, Inc. Agent-based event-driven web server architecture
CN101982955A (en) * 2010-11-19 2011-03-02 深圳华大基因科技有限公司 High-performance file transmission system and method thereof
CN106302554A (en) * 2016-11-08 2017-01-04 郑州云海信息技术有限公司 A kind of socket communication means, device and storage device
CN107147543A (en) * 2017-04-19 2017-09-08 武汉票据交易中心有限公司 A kind of socket communication means of server towards pc client
CN108563493A (en) * 2018-04-12 2018-09-21 郑州云海信息技术有限公司 A kind of event-driven method, device, equipment and readable storage medium storing program for executing
CN109189595A (en) * 2018-09-17 2019-01-11 深圳怡化电脑股份有限公司 Event-handling method, device, equipment and medium based on server
CN111552901A (en) * 2019-02-11 2020-08-18 福建省天奕网络科技有限公司 Method and storage medium for H5 cross-engine client data automation updating
CN111651320A (en) * 2020-05-20 2020-09-11 北京中交兴路信息科技有限公司 High-concurrency connection method and system

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010029548A1 (en) * 2000-04-08 2001-10-11 Geetha Srikantan Method and apparatus for handling events received at a server socket
US7263550B1 (en) * 2000-10-10 2007-08-28 Juniper Networks, Inc. Agent-based event-driven web server architecture
CN101982955A (en) * 2010-11-19 2011-03-02 深圳华大基因科技有限公司 High-performance file transmission system and method thereof
CN106302554A (en) * 2016-11-08 2017-01-04 郑州云海信息技术有限公司 A kind of socket communication means, device and storage device
CN107147543A (en) * 2017-04-19 2017-09-08 武汉票据交易中心有限公司 A kind of socket communication means of server towards pc client
CN108563493A (en) * 2018-04-12 2018-09-21 郑州云海信息技术有限公司 A kind of event-driven method, device, equipment and readable storage medium storing program for executing
CN109189595A (en) * 2018-09-17 2019-01-11 深圳怡化电脑股份有限公司 Event-handling method, device, equipment and medium based on server
CN111552901A (en) * 2019-02-11 2020-08-18 福建省天奕网络科技有限公司 Method and storage medium for H5 cross-engine client data automation updating
CN111651320A (en) * 2020-05-20 2020-09-11 北京中交兴路信息科技有限公司 High-concurrency connection method and system

Also Published As

Publication number Publication date
CN112995198B (en) 2023-04-28

Similar Documents

Publication Publication Date Title
US9998558B2 (en) Method to implement RDMA NVME device
TWI242753B (en) Apparatus, method and system with a graphics-rendering engine having a graphics context manager
KR101855552B1 (en) Global composition system
US7737983B2 (en) GPU pipeline multiple level synchronization controller processor and method
US8122155B1 (en) RDMA write completion semantics
US10521393B2 (en) Remote direct memory access (RDMA) high performance producer-consumer message processing
TWI486787B (en) Method and system of displaying frame
JP2016540268A (en) Technology to track wake clock usage
JP2014517928A (en) Controlling platform power consumption by selectively updating the displayed image
US20200374593A1 (en) Scalable light-weight protocols for wire-speed packet ordering
CN113032080B (en) Page implementation method, application program, electronic device and storage medium
US20090199191A1 (en) Notification to Task of Completion of GSM Operations by Initiator Node
EP4231242A1 (en) Graphics rendering method and related device thereof
CN112187530A (en) Log analysis method and device, electronic equipment and readable storage medium
US20100223419A1 (en) Copy circumvention in a virtual network environment
US20130132618A1 (en) Usb redirection for interrupt transactions
CN103019823A (en) Message queue method for realizing communication between VxWorks and Qt
US8214604B2 (en) Mechanisms to order global shared memory operations
CN112995198A (en) Short-connection communication method and device based on socket
US20210392269A1 (en) Motion sensor in memory
US20120079145A1 (en) Root hub virtual transaction translator
CN112463598A (en) Pressure measurement method and device, electronic equipment and readable storage medium
US11798118B2 (en) Asset caching in cloud rendering computing architectures
CN112486807A (en) Pressure testing method and device, electronic equipment and readable storage medium
WO2023093418A1 (en) Data migration method and apparatus, and electronic device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant