Cobra -- communication between client and server

Source: Internet
Author: User

The basic framework of Cobra has taken shape. The communication between the client and server of cobra can be realized, and the python virtual machine can be run under the control of the client.
Because the client needs to pass two types of independent information to the server: 1. The py source file to be executed; 2. commands to control the execution of virtual machines. Therefore, the Cobra server listens to these two types of information on the two ports, which correspond to ports 6061 and 6060 respectively.
When the Cobra server is started, it waits for the connection from the client on port 6061 and receives the file name to be executed from the client.

At this time, of course, you need to start the Cobra client. The current client is very simple and can hardly be used, as shown in:

"Select Source File" allows you to select the one you want to execute using the Cobra server. PY source file. The next step is similar to the "Next" operation in various debugger operations. The "close" button will disconnect the connection between the Cobra server and the client.
OK. In the first step, select the source file to be executed:

The following simple file is used:

 

Print 'hello'

Through idle, we can see the compiled bytecode instruction sequence of this file:

After the client selects hello. py, it will pass the absolute path of the hello. py file to the server to activate the subsequent actions of the server:

After the server receives the file name of the. py file that the client sends from Port 44311, it starts the python Virtual Machine Process and enters the STANDBY state. It listens to the Client Command on port 6060. The client will receive the status of the server at this time:

We can clearly see that the server is currently executing hello. py, And the bytecode command to be executed is "100 0", which is translated into a user-friendly form of "load_const 0 ".

Now we issue the "Next" command on the client. After the server receives the command, it will execute the next bytecode command, that is, "load_const 0 ".

Before the server executes the second command, the server passes the current status to the client and waits for the client's command on port 6060, the entire bytecode instruction sequence is executed. After the execution is complete, click "close" to disconnect the client from the server. The two lines show that the server has stopped listening on both ports 6060 and 6061.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.