[OpenR8 solution] Socket (Two-way network communication)
  1. Chapter1: Socket introduction

 

Socket is an interface for two-way network communication. It is mainly divided into two types: TCP and UDP. Sockets are different according to the protocol. In the openR8 solution, the TCP protocol is used, so only Introduce the Server and Client of Socket TCP, and its process architecture is shown in Fig. 1.

 

Fig. 1. Relationship between Server and Client.png

Fig. 1. Relationship between Server and Client.

 

 

  1. Chapter2: Socket folder introduction

 

The Socket is located in the solution folder of OpenR8, as shown in Fig. 2, which has two flow files, such as Fig. 3.

  1. server.flow: server solution.
  2. client.flow: client solution.

 

Fig. 2. Socket location.png

Fig. 2. Socket location.

 

Fig. 3. Socket folder.png

Fig. 3. Socket folder.

 

 

  1. Chapter3: server.flow, client.flow — Transfer data between the server and the client

 

Please double-click “R8_Python3.6_CPU.bat or R8_Python3.6_GPU.bat” => “File” => “Open” => “Enter the solution folder under OpenR8” => “Select Socket folder => “Load server.flow”, as shown in Fig. 4,Fig. 5.

 

Fig. 4. Select server.flow.png

Fig. 4. Select server.flow.

 

Fig. 5. Load server.flow.png

Fig. 5. Load server.flow.

 

※ If the field of [Socket_Init] is unload, as shown in Fig. 6, please refer to the Socket library as shown in Fig. 7 and restart R8_Python3.6_CPU.bat or R8_Python3.6_GPU.bat.

 

Fig. 6. Unreferenced Socket library.png

Fig. 6. Unreferenced Socket library.

 

Fig. 7. Check the Socket reference library.png

Fig. 7. Check the Socket reference library.

 

Open a new “R8_Python3.6_CPU.bat” or “R8_Python3.6_GPU.bat”, then click “File” => “Open” => “Enter the solution folder under OpenR8” => “Select Socket folder” => “Load client.flow” , as shown in Fig. 8, Fig. 9.

 

Fig. 8. Select client.flow.png

Fig. 8. Select client.flow.

 

Fig. 9. Load client.flow.png

Fig. 9. Load client.flow.

 

※The server.flow example here mainly receives the client's data, and then returns other data to the client to end the connection; client.flow sends the data to the server, then receives the server's return message, and finally ends the connection, such as Fig. 10.

 

Fig. 10. Solution example relationship.png

Fig. 10. Solution example relationship.

 

Therefore, client.flow first selects the data to be sent to the server (Fig. 11 selects the file as an example, please select the file in your own computer), as shown in Fig. 11.

 

Fig. 11. Select the data to be sent to the Server.png

Fig. 11. Select the data to be sent to the Server.

 

Then select the file that the server will send back to the client after receiving the data (Fig. 12 is only an example of the file selected, please select the file in your computer), as shown in Fig. 12.

 

Fig. 12. Select the data to be sent to the client.png

Fig. 12. Select the data to be sent to the client.

 

First execute server.flow, open the server, and wait for the client to connect, as shown in Fig. 13.

 

Fig. 13. server waiting for client connection.png

Fig. 13. server waiting for client connection.

 

Then execute client.flow, connect to the server, and transfer the file to the server, as shown in Fig. 14.

 

Fig. 14. client sends data to the server.png

Fig. 14. client sends data to the server.

 

Fig. 15. Relationship between operational results and processes.png

Fig. 15. Relationship between operational results and processes.

 

 

  1. Chapter4: Socket function introduction

 

Fig. 16. Socket function.png

Fig. 16. Socket function.

 

The leftmost part of Fig. 16 is the function of the Socket function library. The middle is the process of the server side, and the right side is the process of the client side.

  1. “Socket_Init”: Initialize a socket object.
  2. “Socket_Bind”: That is, the bind() function in the socket can be set to use the TCP or UDP protocol and which port to use, to limit the use of the server.
  3. “Socket_Listen”: This is the bind() function in socket, which can be set to use the TCP or UDP protocol and which port to use. Limit the use of the server side.
  4. “Socket_Read”: This is the recv() function in the socket, which is responsible for reading the content transmitted through the socket.
  5. “Socket_Write”: This is the send() function in the socket, which is responsible for transferring data through the socket.
  6. “Socket_Close”: End the socket connection.
  7. “Socket_Connect”: This is the connect() function in the socket, using socket to connect to the server. Limit the use of the client side.

 

※Because the example here is simple reading and transmission, if you want to read or transfer it all the time, you need to change the process yourself, such as loops.


Recommended Article

1.
OpenR8 Community Edition - AI Software for Everyone (Free Download)