Method, device and equipment for remotely controlling Lua virtual machine and storage medium
By building virtual machine connection requests and refactoring the Lua virtual machine, remote control of the Lua virtual machine is realized, the problem of lack of remote control methods in the existing technology is solved, and development efficiency and convenience are improved.
Patent Information
- Application Number
- CN202510038454.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-10
- Publication Date
- 2025-05-16
AI Technical Summary
In the prior art, Lua virtual machines lack remote control methods, resulting in each Lua virtual machine that needs remote control needs to develop a remote interface separately, which increases development cost and complexity.
By building virtual machine connection requests, establish a connection to the controlled Lua virtual machine, and refactor the virtual machine after the connection is successful, redirecting its input and output interfaces to achieve remote control.
It improves the convenience and flexibility of remote control of Lua virtual machines, reduces the difficulty of users, and improves the efficiency of remote development.
Smart Images

Figure CN120010991A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of remote control technology, and in particular to a method, device, equipment and storage medium for remotely controlling a Lua virtual machine. Background Art
[0002] Lua is a compact scripting language that is completely implemented in C language. It can be compiled and run on almost all operating systems and platforms, providing flexible expansion and customization capabilities for applications. In view of this, Lua is widely used, but generally integrated with localized interfaces. Lua itself does not provide remote control methods, which means that each Lua virtual machine that needs remote control needs to develop a corresponding remote interface separately, increasing development costs and complexity.
[0003] In the prior art, remote control can be achieved by using a console tool, but secondary development of the console is required. This secondary development not only increases the technical difficulty, but may also cause system instability. Therefore, a simple and reliable Lua virtual machine remote control method is needed. Summary of the invention
[0004] The embodiment of the present invention provides a method for remotely controlling a Lua virtual machine, which can improve the convenience and flexibility of remote control of the Lua virtual machine, thereby reducing the difficulty of use for users and improving remote development efficiency.
[0005] In a first aspect, an embodiment of the present invention provides a method for remotely controlling a Lua virtual machine, comprising:
[0006] Constructing a virtual machine connection request according to the received virtual machine connection related parameters, sending the virtual machine connection request to the monitoring service port of the controlled virtual machine, and receiving a connection response result returned by the controlled virtual machine; wherein the monitoring service port is used to monitor the virtual machine connection request of the control end;
[0007] When the connection response result is a successful connection, reconstructing the controlled virtual machine based on the operating environment of the controlled virtual machine; wherein the number of the controlled virtual machines may be one or more;
[0008] Obtain tasks to be executed according to preset virtual machine control requirements, send the tasks to be executed to corresponding reconstructed controlled virtual machines, so that the controlled virtual machines execute the tasks to be executed, and receive task execution results returned by the controlled virtual machines after the tasks are executed.
[0009] Further, when the controlled virtual machine contains a file system, the reconstructing the controlled virtual machine includes:
[0010] Constructing a control program, and redirecting the input interface and the output interface of the controlled virtual machine to the control program;
[0011] A first receiving thread and a first sending thread are established so that the control program receives control information of the control end from the redirected input interface through the first receiving thread, and sends feedback information of the controlled virtual machine to the control end from the redirected output interface through the first sending thread.
[0012] Further, when the controlled virtual machine does not contain a file system, the reconstructing the controlled virtual machine includes:
[0013] Reconstructing the input interface and the output interface of the controlled virtual machine;
[0014] A second receiving thread is established, so that the controlled virtual machine receives the control information of the control end from the reconstructed input interface through the second receiving thread, and sends the feedback information of the controlled virtual machine to the control end through the reconstructed output interface.
[0015] Further, constructing a virtual machine connection request according to the received virtual machine connection related parameters, sending the virtual machine connection request to the listening service port of the controlled virtual machine, and receiving a connection response result returned by the controlled virtual machine includes:
[0016] Receive virtual machine connection related parameters; wherein the virtual machine connection related parameters include the command line prompt, IP address and monitoring service port number of the controlled virtual machine;
[0017] Building a virtual machine connection request based on the virtual machine connection related parameters, and sending the virtual machine connection request to the monitoring service port of the controlled virtual machine;
[0018] Receive a connection response result returned by the controlled virtual machine; wherein the connection response result includes a connection success and a connection failure.
[0019] Furthermore, the sending of the tasks to be executed to the corresponding reconstructed controlled virtual machines respectively includes:
[0020] Constructing a task execution request; wherein the input parameters of the task execution request are the identification information of the controlled virtual machine corresponding to the task to be executed, the script to be executed, and the time to wait for the script execution to return;
[0021] The task execution request is sent to the corresponding reconstructed controlled virtual machine.
[0022] Furthermore, after receiving the task execution result returned by the controlled virtual machine after the task execution is completed, the method further includes:
[0023] Constructing a resource release request; wherein the input parameter of the resource release request is the virtual machine identification information of the resource to be released;
[0024] The connection with the controlled virtual machine is disconnected based on the resource release request, and all resources used in the connection process and the data transmission process are recovered.
[0025] Furthermore, the method further comprises:
[0026] Constructing a task query request; wherein the input parameter of the task query request is the identification information of the controlled virtual machine corresponding to the task to be queried;
[0027] The task query request is sent to the corresponding controlled virtual machine, and the task query result returned by the controlled virtual machine is received; wherein the task query result includes the task execution status and the task execution result.
[0028] In a second aspect, an embodiment of the present invention provides a device for remotely controlling a Lua virtual machine, comprising:
[0029] A virtual machine connection module, used to construct a virtual machine connection request according to the received virtual machine connection related parameters, send the virtual machine connection request to the monitoring service port of the controlled virtual machine, and receive a connection response result returned by the controlled virtual machine; wherein the monitoring service port is used to monitor the virtual machine connection request of the control end;
[0030] a virtual machine reconstruction module, configured to reconstruct the controlled virtual machine based on the operating environment of the controlled virtual machine when the connection response result is a successful connection; wherein the number of the controlled virtual machines may be one or more;
[0031] The virtual machine control module is used to obtain the tasks to be executed according to the preset virtual machine control requirements, send the tasks to be executed to the corresponding reconstructed controlled virtual machines respectively, so that the controlled virtual machines can execute the tasks to be executed respectively, and receive the task execution results returned by the controlled virtual machines after the task execution is completed.
[0032] In a third aspect, an embodiment of the present invention provides an electronic device, including:
[0033] Memory for storing computer programs;
[0034] A processor, configured to execute the computer program;
[0035] Wherein, when the processor executes the computer program, the method for remotely controlling the Lua virtual machine described in any one of the first aspects above is implemented.
[0036] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed, the method for remotely controlling a Lua virtual machine as described in any one of the first aspects above is implemented.
[0037] Compared with the prior art, a method for remotely controlling a Lua virtual machine provided by an embodiment of the present invention has the following beneficial effects: constructing a virtual machine connection request according to received virtual machine connection-related parameters, sending the virtual machine connection request to the listening service port of the controlled virtual machine, and receiving a connection response result returned by the controlled virtual machine; wherein the listening service port is used to listen to the virtual machine connection request of the control end; when the connection response result is a successful connection, reconstructing the controlled virtual machine based on the operating environment of the controlled virtual machine; wherein the number of the controlled virtual machines can be one or more; obtaining tasks to be executed according to preset virtual machine control requirements, sending the tasks to be executed to the corresponding reconstructed controlled virtual machines respectively, so that the controlled virtual machines respectively execute the tasks to be executed, and receiving the task execution results returned by the controlled virtual machine after the task execution is completed; the present invention can improve the convenience and flexibility of Lua virtual machine remote control, thereby reducing the difficulty of use for users and improving remote development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical features of the embodiments of the present invention, the drawings required for use in the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0039] Figure 1 It is a flow chart of an embodiment of a method for remotely controlling a Lua virtual machine provided by the present invention;
[0040] Figure 2 It is a structural schematic diagram of an embodiment of a device for remotely controlling a Lua virtual machine provided by the present invention;
[0041] Figure 3 It is a structural schematic diagram of an embodiment of an electronic device provided by the present invention. DETAILED DESCRIPTION
[0042] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0043] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0044] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which the present invention belongs. The terms used herein are only for the purpose of describing the embodiments of the present invention and are not intended to limit the present invention.
[0045] In a first aspect, an embodiment of the present invention provides a method for remotely controlling a Lua virtual machine, see Figure 1 , which is a flow chart of an embodiment of a method for remotely controlling a Lua virtual machine provided by the present invention.
[0046] like Figure 1 As shown, the method comprises the following steps:
[0047] S1: construct a virtual machine connection request according to the received virtual machine connection related parameters, send the virtual machine connection request to the monitoring service port of the controlled virtual machine, and receive a connection response result returned by the controlled virtual machine; wherein the monitoring service port is used to monitor the virtual machine connection request of the control end;
[0048] S2: When the connection response result is a successful connection, reconstructing the controlled virtual machine based on the operating environment of the controlled virtual machine; wherein the number of the controlled virtual machines may be one or more;
[0049] S3: Obtain tasks to be executed according to preset virtual machine control requirements, send the tasks to be executed to corresponding reconstructed controlled virtual machines, so that the controlled virtual machines execute the tasks to be executed, and receive task execution results returned by the controlled virtual machines after the tasks are executed.
[0050] In a specific implementation, a listening service port is first constructed on the controlled virtual machine to listen to the virtual machine connection request from the control end. The control end constructs a virtual machine connection request according to the received virtual machine connection-related parameters. The virtual machine connection-related parameters specify the target virtual machine to be connected, and sends it to the listening service port of the controlled virtual machine, and waits for the response of the controlled virtual machine. When the response result is a successful connection, it is reconstructed according to the operating environment of the controlled virtual machine. The number of controlled virtual machines can be one or more, and multiple virtual machines can be connected simultaneously according to different task requirements. Each controlled virtual machine is reconstructed according to its specific operating environment. After completing the reconstruction of the controlled virtual machine, the task to be executed is determined according to the preset virtual machine control requirements, and it is sent to the corresponding reconstructed controlled virtual machine. After receiving the task, the controlled virtual machine will start execution immediately, and after execution, the task execution result will be returned to the control end.
[0051] In summary, the present invention constructs a virtual machine connection request according to the received virtual machine connection related parameters, sends the virtual machine connection request to the listening service port of the controlled virtual machine, and receives the connection response result returned by the controlled virtual machine; when the connection response result is a successful connection, the controlled virtual machine is reconstructed based on the operating environment of the controlled virtual machine; wherein the number of controlled virtual machines can be one or more; tasks to be executed are obtained according to preset virtual machine control requirements, and the tasks to be executed are respectively sent to the corresponding reconstructed controlled virtual machines, so that the controlled virtual machines respectively execute the tasks to be executed, and receive the task execution results returned by the controlled virtual machine after the task execution is completed; the present invention retains the original Lua virtual machine usage mode to the greatest extent possible, and the original Lua script can be fully reused. The entire device environment can flexibly realize the design of multiple auxiliary control scenarios, which can improve the convenience of Lua virtual machine remote control, and greatly extend the flexibility of use, thereby reducing the user's difficulty of use and improving remote development efficiency. . . . .
[0052] In an optional implementation, when the controlled virtual machine includes a file system, reconstructing the controlled virtual machine includes:
[0053] Constructing a control program, and redirecting the input interface and the output interface of the controlled virtual machine to the control program;
[0054] A first receiving thread and a first sending thread are established so that the control program receives control information of the control end from the redirected input interface through the first receiving thread, and sends feedback information of the controlled virtual machine to the control end from the redirected output interface through the first sending thread.
[0055] Specifically, for devices that contain a file system and do not want to change the original Lua virtual machine, a control program is plugged in. By redirecting the input interface and output interface of the original Lua virtual machine to the control program, the control program connects the input and output to the network interface, thereby realizing the server mode. In this way, without directly modifying the original virtual machine, it can receive input from the remote control end and send output to the remote end.
[0056] Furthermore, two threads are established, including a first receiving thread and a first sending thread. After the virtual machine establishes a connection with the control end, the corresponding socket handle is obtained. The socket handle will become the channel for data communication between the virtual machine and the control end. The Lua virtual machine is started using a channel interface similar to popen, and the pipe operation handle hFile is obtained to take over the input and output of the Lua virtual machine to realize the control and interaction of the virtual machine.
[0057] Specifically, the first receiving thread calls the recv function to receive data from the socket, and calls the fput function to forward the data to the virtual machine's input pipe hFile. The script data sent by the remote control end can be executed by the Lua virtual machine. The first sending thread calls the fgets function to read feedback data from the virtual machine's output pipe hFile, and calls the send function to send the data to the remote control end through the socket. The remote control end can obtain the feedback results of the controlled virtual machine in real time.
[0058] The above-mentioned method of reconstructing the virtual machine makes little change to the original system, is suitable for an environment that has been deployed and is running stably, and avoids the risks that may be caused by directly modifying the virtual machine.
[0059] In an optional implementation, when the controlled virtual machine does not have a file system, reconstructing the controlled virtual machine includes:
[0060] Reconstructing the input interface and the output interface of the controlled virtual machine;
[0061] A second receiving thread is established, so that the controlled virtual machine receives the control information of the control end from the reconstructed input interface through the second receiving thread, and sends the feedback information of the controlled virtual machine to the control end through the reconstructed output interface.
[0062] Specifically, for a low-end environment without a file system, or an environment in which a Lua virtual machine can be reconstructed, the embodiment of the present invention directly reconstructs the input interface Lua_readline and the output interface Lua_writestring of the Lua virtual machine to map them into a network interface to provide network services, and then establishes a second receiving thread and a receiving buffer. Lua_readline is an interface for reading data from a standard input, which is reconstructed into an interface that can receive Lua script instructions through a socket. The second receiving thread receives data from a remote control terminal and saves it into a receiving buffer. When the Lua virtual machine calls Lua_readline, the remote Lua instruction is extracted from the buffer and returned to the Lua virtual machine.
[0063] Furthermore, Lua_writestring is the interface for the Lua virtual machine to write information to the standard output. It is reconstructed so that it no longer writes to the standard output, but sends the data to the previously established socket connection, and operates the socket through the send function to send the information to the remote end.
[0064] The above-mentioned method of reconstructing the virtual machine more directly connects the Lua virtual machine to the network, is suitable for low-end devices with limited resources, can give full play to the performance of the device, and improve the response speed of the system.
[0065] In an optional implementation, the step of constructing a virtual machine connection request according to the received virtual machine connection related parameters, sending the virtual machine connection request to a listening service port of the controlled virtual machine, and receiving a connection response result returned by the controlled virtual machine includes:
[0066] Receive virtual machine connection related parameters; wherein the virtual machine connection related parameters include the command line prompt, IP address and monitoring service port number of the controlled virtual machine;
[0067] Building a virtual machine connection request based on the virtual machine connection related parameters, and sending the virtual machine connection request to the monitoring service port of the controlled virtual machine;
[0068] Receive a connection response result returned by the controlled virtual machine; wherein the connection response result includes a connection success and a connection failure.
[0069] Specifically, in the process of connecting with the controlled virtual machine, firstly, a virtual machine connection request Rc_init is constructed according to the virtual machine connection related parameters, and the request is sent to the listening service port of the controlled virtual machine. After the listening service port listens to the virtual machine connection request, a connection is established with the control end, and a connection response result is returned. The response result may be a successful connection or a connection failure. If the connection with the Lua virtual machine is successful, an Rc_obj handle returned by the virtual machine is received. The Rc_obj handle contains some necessary information of the virtual machine. If the connection fails, the virtual machine returns a null value, indicating that the connection failed.
[0070] For example, the pseudo code of the Rc_obj structure is as follows:
[0071] typedef struct{
[0072] / / The remote Lua virtual machine IP corresponding to this structure, MAX_IP_ADDR_LEN is defined as the maximum IP address length
[0073] char m_cRemoteIP[MAX_IP_ADDR_LEN+1];
[0074] / / The service port provided by the remote Lua virtual machine
[0075] unsinged short m_usRemotePort;
[0076] / / The line prompt of the remote Lua virtual machine
[0077] char m_cRemotePromt[MAX_PROMT_LEN+1];
[0078] / / After the task execution request is finally completed, the remote Lua virtual machine returns the information
[0079] char m_cLastResultInfo[MAX_RESULT_INFO_LEN+1];
[0080] / / The local network interface handle to establish a network connection with the remote Lua virtual machine
[0081] int m_iSocketId;
[0082] / / Flag whether to exit the return thread of receiving the remote Lua virtual machine
[0083] bool m_bExitRecvProc;
[0084] / / Receive the handle of the data thread returned by the remote Lua virtual machine
[0085] void* m_hRecv;
[0086] }Rc_obj;
[0087] typedef Rc_obj*hRc_obj;
[0088] / / hRc_obj is a pointer to the Rc_obj address
[0089] The virtual machine connection related parameters include the command line prompt, IP address and listening service port number of the controlled virtual machine. Among them, the command line prompt strPromt is a string parameter, which represents the prompt of the remote Lua virtual machine command line. The prompt is used to distinguish the command execution results of the remote Lua virtual machine after the connection is established. Different prompts can help users quickly identify different remote virtual machine environments, so as to more accurately process the execution results; the IP address strRemoteIP is also a string parameter, which is the IP address of the remote Lua virtual machine. By specifying the IP address, the target remote virtual machine can be accurately found for connection; the listening service port number usRemotePort is a short integer parameter, which represents the network port number provided by the remote Lua virtual machine for listening to virtual machine connection requests.
[0090] In an optional implementation manner, sending the tasks to be executed to the corresponding reconstructed controlled virtual machines respectively includes:
[0091] Constructing a task execution request; wherein the input parameters of the task execution request are the identification information of the controlled virtual machine corresponding to the task to be executed, the script to be executed, and the time to wait for the script execution to return;
[0092] The task execution request is sent to the corresponding reconstructed controlled virtual machine.
[0093] Specifically, when passing a local Lua script to a remote Lua virtual machine for execution, it is necessary to construct a task execution request Rc_Exce, which receives three input parameters, including the identification information of the controlled virtual machine corresponding to the task to be executed, the script to be executed, and the time to wait for the script to be executed and returned. The identification information hRc_obj of the controlled virtual machine is a pointer to the Rc_obj address, which ensures that the script can be accurately sent to the correct remote virtual machine for execution; the script to be executed strLua is a string parameter, which is the script that actually needs to be executed. The user can pass the Lua script that needs to be executed in the remote virtual machine as a string into this parameter; the time to wait for the script to be executed uiWait is an unsigned integer, indicating the time the control end waits for the return of the script execution. If it is 0, it means not waiting for the result. You can choose whether to wait for the script execution result according to actual needs.
[0094] It should be noted that the return result of this request includes two parts. The first result is an integer data, which represents the return status of the script execution. If the result is 0, it means that the current function is in asynchronous processing mode. If the result is 1, it means that the script execution result has been obtained. If the result is -1, it means that an exception has occurred during the function execution process. If the result is -2, it means that the waiting for the script execution result has timed out. This result allows the user to understand the status of the script execution so that corresponding processing can be performed. The second result is string data, which is the print information of the Lua virtual machine after the script is executed. This information can help the control-end user understand the execution status of the script in the remote virtual machine, which is very helpful for debugging and troubleshooting.
[0095] In an optional implementation manner, after receiving the task execution result returned by the controlled virtual machine after the task execution is completed, the method further includes:
[0096] Constructing a resource release request; wherein the input parameter of the resource release request is the virtual machine identification information of the resource to be released;
[0097] The connection with the controlled virtual machine is disconnected based on the resource release request, and all resources used in the connection process and the data transmission process are recovered.
[0098] Specifically, after receiving the task execution result returned by the controlled virtual machine after the task execution is completed, it is necessary to disconnect the connection with the Lua virtual machine and recycle local system resources. It is necessary to construct a resource release request Rc_Deinit, which receives an input parameter, which is the virtual machine identification information hRc_obj of the resource to be released. According to the resource release request, the occupied system resources can be released in time to avoid resource waste and potential resource leakage problems.
[0099] It is understandable that this request does not return any result. Its main function is to clean up resources when there is no need to connect to the remote virtual machine.
[0100] In an optional embodiment, the method further includes:
[0101] Constructing a task query request; wherein the input parameter of the task query request is the identification information of the controlled virtual machine corresponding to the task to be queried;
[0102] The task query request is sent to the corresponding controlled virtual machine, and the task query result returned by the controlled virtual machine is received; wherein the task query result includes the task execution status and the task execution result.
[0103] Specifically, during the task execution process, it is often necessary to monitor the task execution status on the remote virtual machine. The embodiment of the present invention can achieve this function through a task query request. First, a task query request Rc_GetLastRunInfo is constructed. The input parameter of the request is the identification information of the controlled virtual machine, which is used to specify the virtual machine to be queried. The task query request is sent to the corresponding controlled virtual machine, and the task execution status and task execution result returned by it are received; wherein the task execution status is an integer data, which is used to indicate whether an exception has occurred in the script execution, and the task execution result is a string data, which is used to indicate the output result of the virtual machine after the task is completed.
[0104] The following is an embodiment of remote control using the method of remotely controlling a Lua virtual machine of the present invention. Assume that there are three virtual machines, namely virtual machine LuaA, virtual machine LuaB and virtual machine LuaC. There is a LuaA library on virtual machine LuaA. The specific control requirement is to first execute the Func call of the LuaA library on virtual machine LuaA, then obtain the system time of virtual machine LuaB, and finally execute the sum from 0 to 100 on virtual machine LuaC and print the result.
[0105] The following Lua script can be executed on the control side to control the controlled virtual machine to complete the above series of tasks:
[0106] / / Establish connections with virtual machines LuaA, LuaB and LuaC respectively
[0107] hLuaA=Rc_init('192.168.1.2',20000,'LuaA')
[0108] hLuaB=Rc_init('192.168.1.3',30000,'LuaB')
[0109] hLuaC=Rc_init('192.168.1.4',40000,'LuaC')
[0110] / / Execute LuaA.Func function on virtual machine LuaA
[0111] Rc_Exce(hLuaA,'LuaA.Func()')
[0112] / / Get the execution result of LuaA.Func and print it
[0113] strLastInfo=Rc_GetLastRunInfo(hLuaA)
[0114] print(strLastInfo)
[0115] / / Print the system time of the virtual machine LuaB
[0116] Rc_Exce(hLuaB,'print(os.date())')
[0117] strLastInfo=Rc_GetLastRunInfo(hLuaB)
[0118] print(strLastInfo)
[0119] / / Run the script on the virtual machine LuaC
[0120] strLuaInfo=[[
[0121] iRet=0
[0122] for i=0,100do
[0123] iRet=iRet+i
[0124] end ]]
[0126] Rc_Exce(hLuaC,strLuaInfo)
[0127] / / Print the calculation result iRet and return it to the control terminal
[0128] Rc_Exce(hLuaC,'print(iRet)')
[0129] strLastInfo=Rc_GetLastRunInfo(hLuaC)
[0130] print(strLastInfo)
[0131] / / Finally release all resources
[0132] Rc_Deinit(hLuaA)
[0133] Rc_Deinit(hLuaB)
[0134] Rc_Deinit(hLuaC)
[0135] It can be seen that the method for remotely controlling the Lua virtual machine using the embodiment of the present invention can flexibly utilize the master script to dynamically regenerate the execution script of the controlled end in real time, so that the controlled end does not simply execute some statements, but can utilize the flexibility of Lua script design to dynamically generate scripts with specific logic on the control end for these controlled ends to execute, and can even directly take the original scripts of each virtual machine to the master control for direct management, and through the serial execution process of the control end, simply and flexibly implement the interactive design of various complex concurrent services.
[0136] In a second aspect, an embodiment of the present invention provides a device for remotely controlling a Lua virtual machine, see Figure 2 , which is a structural diagram of an embodiment of a device for remotely controlling a Lua virtual machine provided by the present invention.
[0137] like Figure 2 As shown, the device comprises:
[0138] The virtual machine connection module 21 is used to construct a virtual machine connection request according to the received virtual machine connection related parameters, send the virtual machine connection request to the monitoring service port of the controlled virtual machine, and receive the connection response result returned by the controlled virtual machine; wherein the monitoring service port is used to monitor the virtual machine connection request of the control end;
[0139] A virtual machine reconstruction module 22, configured to reconstruct the controlled virtual machine based on the operating environment of the controlled virtual machine when the connection response result is a successful connection; wherein the number of the controlled virtual machines may be one or more;
[0140] The virtual machine control module 23 is used to obtain the tasks to be executed according to the preset virtual machine control requirements, send the tasks to be executed to the corresponding reconstructed controlled virtual machines, so that the controlled virtual machines can execute the tasks to be executed respectively, and receive the task execution results returned by the controlled virtual machines after the task execution is completed.
[0141] In an optional implementation, when the controlled virtual machine contains a file system, the virtual machine reconstruction module 22 is used to:
[0142] Constructing a control program, and redirecting the input interface and the output interface of the controlled virtual machine to the control program;
[0143] A first receiving thread and a first sending thread are established so that the control program receives control information of the control end from the redirected input interface through the first receiving thread, and sends feedback information of the controlled virtual machine to the control end from the redirected output interface through the first sending thread.
[0144] In an optional implementation, when the controlled virtual machine does not have a file system, the virtual machine reconstruction module 22 is used to:
[0145] Reconstructing the input interface and the output interface of the controlled virtual machine;
[0146] A second receiving thread is established, so that the controlled virtual machine receives the control information of the control end from the reconstructed input interface through the second receiving thread, and sends the feedback information of the controlled virtual machine to the control end through the reconstructed output interface.
[0147] In an optional implementation, the virtual machine connection module 21 is further used for:
[0148] Receive virtual machine connection related parameters; wherein the virtual machine connection related parameters include the command line prompt, IP address and monitoring service port number of the controlled virtual machine;
[0149] Building a virtual machine connection request based on the virtual machine connection related parameters, and sending the virtual machine connection request to the monitoring service port of the controlled virtual machine;
[0150] Receive a connection response result returned by the controlled virtual machine; wherein the connection response result includes a connection success and a connection failure.
[0151] In an optional implementation, the virtual machine control module 23 is further used to:
[0152] Constructing a task execution request; wherein the input parameters of the task execution request are the identification information of the controlled virtual machine corresponding to the task to be executed, the script to be executed, and the time to wait for the script execution to return;
[0153] The task execution request is sent to the corresponding reconstructed controlled virtual machine.
[0154] In an optional implementation, the device further includes a resource releasing module, configured to:
[0155] Constructing a resource release request; wherein the input parameter of the resource release request is the virtual machine identification information of the resource to be released;
[0156] The connection with the controlled virtual machine is disconnected based on the resource release request, and all resources used in the connection process and the data transmission process are recovered.
[0157] In an optional implementation, the device further includes a task query module, which is used to:
[0158] Constructing a task query request; wherein the input parameter of the task query request is the identification information of the controlled virtual machine corresponding to the task to be queried;
[0159] The task query request is sent to the corresponding controlled virtual machine, and the task query result returned by the controlled virtual machine is received; wherein the task query result includes the task execution status and the task execution result.
[0160] In a third aspect, an embodiment of the present invention provides an electronic device, see Figure 3 , which is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.
[0161] like Figure 3 As shown, the device includes:
[0162] A memory 31, used for storing computer programs;
[0163] A processor 32, configured to execute the computer program;
[0164] When the processor 32 executes the computer program, the method for remotely controlling the Lua virtual machine as described in any of the above embodiments is implemented.
[0165] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory 31 and executed by the processor 32 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the electronic device.
[0166] The processor 32 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0167] The memory 31 can be used to store the computer program and / or module, and the processor 32 realizes various functions of the electronic device by running or executing the computer program and / or module stored in the memory 31, and calling the data stored in the memory 31. The memory 31 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory 31 can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0168] It should be noted that the above electronic device includes, but is not limited to, a processor and a memory. Those skilled in the art can understand that Figure 3 The structural diagram is merely an example of the electronic device described above and does not constitute a limitation on the electronic device, and may include more components than shown in the figure, or a combination of certain components, or different components.
[0169] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed, the method for remotely controlling a Lua virtual machine as described in any of the above embodiments is implemented.
[0170] It should be understood that the present invention implements all or part of the processes in the above-mentioned method of remotely controlling the Lua virtual machine, and can also be completed by instructing related hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned method of remotely controlling the Lua virtual machine when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal and software distribution medium, etc.
[0171] The above description is only a preferred embodiment of the present invention, but the protection scope of the present invention is not limited thereto. It should be pointed out that for those skilled in the art, several equivalent obvious variations and / or equivalent substitutions can be made without departing from the technical principles of the present invention. These obvious variations and / or equivalent substitutions should also be regarded as the protection scope of the present invention.
Claims
1. A method for remotely controlling a Lua virtual machine, characterized in that: include: Constructing a virtual machine connection request according to the received virtual machine connection related parameters, sending the virtual machine connection request to the monitoring service port of the controlled virtual machine, and receiving a connection response result returned by the controlled virtual machine; wherein the monitoring service port is used to monitor the virtual machine connection request of the control end; When the connection response result is a successful connection, reconstructing the controlled virtual machine based on the operating environment of the controlled virtual machine; wherein the number of the controlled virtual machines may be one or more; Obtain tasks to be executed according to preset virtual machine control requirements, send the tasks to be executed to corresponding reconstructed controlled virtual machines, so that the controlled virtual machines execute the tasks to be executed, and receive task execution results returned by the controlled virtual machines after the tasks are executed.
2. The method for remotely controlling a Lua virtual machine according to claim 1, wherein: When the controlled virtual machine contains a file system, the reconstructing the controlled virtual machine includes: Constructing a control program, and redirecting the input interface and the output interface of the controlled virtual machine to the control program; A first receiving thread and a first sending thread are established so that the control program receives control information of the control end from the redirected input interface through the first receiving thread, and sends feedback information of the controlled virtual machine to the control end from the redirected output interface through the first sending thread.
3. The method for remotely controlling a Lua virtual machine according to claim 1, wherein: When the controlled virtual machine does not have a file system, reconstructing the controlled virtual machine includes: Reconstructing the input interface and the output interface of the controlled virtual machine; A second receiving thread is established, so that the controlled virtual machine receives the control information of the control end from the reconstructed input interface through the second receiving thread, and sends the feedback information of the controlled virtual machine to the control end through the reconstructed output interface.
4. The method for remotely controlling a Lua virtual machine according to claim 1, wherein: The step of constructing a virtual machine connection request according to the received virtual machine connection related parameters, sending the virtual machine connection request to the monitoring service port of the controlled virtual machine, and receiving a connection response result returned by the controlled virtual machine includes: Receive virtual machine connection related parameters; wherein the virtual machine connection related parameters include the command line prompt, IP address and monitoring service port number of the controlled virtual machine; Building a virtual machine connection request based on the virtual machine connection related parameters, and sending the virtual machine connection request to the monitoring service port of the controlled virtual machine; Receive a connection response result returned by the controlled virtual machine; wherein the connection response result includes a connection success and a connection failure.
5. The method for remotely controlling a Lua virtual machine according to claim 1, wherein: The sending the tasks to be executed to the corresponding reconstructed controlled virtual machines respectively includes: Constructing a task execution request; wherein the input parameters of the task execution request are the identification information of the controlled virtual machine corresponding to the task to be executed, the script to be executed, and the time to wait for the script execution to return; The task execution request is sent to the corresponding reconstructed controlled virtual machine.
6. The method for remotely controlling a Lua virtual machine according to claim 1, wherein: After receiving the task execution result returned by the controlled virtual machine after the task execution is completed, the method further includes: Constructing a resource release request; wherein the input parameter of the resource release request is the virtual machine identification information of the resource to be released; The connection with the controlled virtual machine is disconnected based on the resource release request, and all resources used in the connection process and the data transmission process are recovered.
7. The method for remotely controlling a Lua virtual machine according to claim 1, wherein: The method further comprises: Constructing a task query request; wherein the input parameter of the task query request is the identification information of the controlled virtual machine corresponding to the task to be queried; The task query request is sent to the corresponding controlled virtual machine, and the task query result returned by the controlled virtual machine is received; wherein the task query result includes the task execution status and the task execution result.
8. A device for remotely controlling a Lua virtual machine, characterized in that: include: A virtual machine connection module, used to construct a virtual machine connection request according to the received virtual machine connection related parameters, send the virtual machine connection request to the monitoring service port of the controlled virtual machine, and receive a connection response result returned by the controlled virtual machine; wherein the monitoring service port is used to monitor the virtual machine connection request of the control end; a virtual machine reconstruction module, configured to reconstruct the controlled virtual machine based on the operating environment of the controlled virtual machine when the connection response result is a successful connection; wherein the number of the controlled virtual machines may be one or more; The virtual machine control module is used to obtain the tasks to be executed according to the preset virtual machine control requirements, send the tasks to be executed to the corresponding reconstructed controlled virtual machines respectively, so that the controlled virtual machines can execute the tasks to be executed respectively, and receive the task execution results returned by the controlled virtual machines after the task execution is completed.
9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program; Wherein, when the processor executes the computer program, the method for remotely controlling a Lua virtual machine as described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the method for remotely controlling a Lua virtual machine according to any one of claims 1 to 7 is implemented.