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.
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.
- server.flow: server solution.
- client.flow: client solution.
Fig. 2. Socket location.
Fig. 3. Socket folder.
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.
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.
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.
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.
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.
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.
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.
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.
Fig. 15. Relationship between operational results and processes.
Chapter4: Socket function introduction
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.
- “Socket_Init”: Initialize a socket object.
- “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.
- “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.
- “Socket_Read”: This is the recv() function in the socket, which is responsible for reading the content transmitted through the socket.
- “Socket_Write”: This is the send() function in the socket, which is responsible for transferring data through the socket.
- “Socket_Close”: End the socket connection.
- “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.