Tuto WINDEV 25

418 Part 7: Advanced programming Practical example The programming of sockets will be presented via the unit example named "Using sockets". Example test ▶ Open the unit example named "Using sockets". ▶ Run the test of "WIN_Socket" window. A message will be sent from computer B to computer A. Computer A is the Server application and computer B is the Client application. 1. On computer A, click the "Create" button to create the socket. 2. Computer B can connect to the socket created by computer A. All you have to do is click the "Connect" button (in Computer B section). 3. Computer B sends a message to computer A: • Type message to send in the "Sentence to send to computer A" area. • Click the "Send" button found in the "Computer B" area. 4.  To retrieve the message on computer A, click the "Get" button found in the "Computer A" area. 5. Click the "Disonnect" buttons to disconnect the two computers. ▶ Stop the window test to go back to the editor. Studying the code used ▶ Let’s study the code of the different buttons that have been used. ▶ First of all, we are going to study the processes performed by the socket server (computer A). 1. Display the code of "Create" button found in the "Computer A" area: • Select the "Create" button. • Press F2 to display the events. 2.  In the "Click" event, you will see SocketCreate , which is used to create the socket. Close the code editor. 3. Display the code of "Get" button found in the "Computer A" area: • Select the "Get" button. • Press F2 to display the events. 4.  The following code is used in the "Click" event: EDT_SentenceReceivedFromComputerB = SocketRead ... ("ComputerA", False, 2000) IF EDT_SentenceReceivedFromComputerB <> "" THEN Info("Message received from IP address # "+... SocketClientInfo("ComputerA", SocketAddress)) END You will notice the presence of SocketRead that is used to read the socket that was created beforehand. The message read is immediately displayed in the "EDT_ SentenceReceivedFromComputerB" control. Close the code editor.

RkJQdWJsaXNoZXIy NDQ0OA==