- The simplified server
- Step 1: Creating the socket
- Step 2: Exchanging data
- Step 3: Closing the socket
- Transmission mode of information
Socket: Creating a simplified socket server
WINDEV gives you the ability to create a simplified socket server. This server communicates with a single client computer at a time
. This type of application is very useful when two remote applications must communicate.
: WINDEV also allows you to create a more complex socket server (standard socket server), used to manage the connection of several client computers simultaneously. For more details, see Standard socket server
Step 1: Creating the socket
To create the socket, the server uses SocketCreate
. A socket is bound to a specific port. To easily use sockets programmatically on the server, specify the socket name.
The client machine will connect to the socket to exchange data. The connection will be actually established at the first data exchange between the two machines (i.e. when the server reads information for the first time).
The connection is established the first time SocketRead
reads information on the server successfully.
Step 2: Exchanging data
When two machines use the same socket, a communication stream is established between them. These two machines can read from and write character strings to the socket.
Remark: To avoid locking the applications, the management of incoming messages is often performed by a specific thread (for more details, see Managing the threads
Caution: To start a read operation, a write operation must have been done previously. For example:
- The client machine writes to the socket: it sends a request to the server.
- The server reads data from the socket in a thread. When a message is received, it is processed by the server.
- If a response to the message is required, the server identifies the client computer (SocketClientInfo) and sends a response.
Step 3: Closing the socket
To end the communication, the server can close the socket with SocketClose
Remark: the socket can also be closed by the client machine.
Transmission mode of information
The transmission mode of the message defines the mode used to specify the length of the message.
Several methods can be used to define the length of message during the communication between sockets.
Method 1: WINDEV mode: By default, the number of characters in the message is specified at the beginning of message. This transmission mode is recommended when the sockets are used to communicate between two WINDEV applications.
The message has the following format: "11\r\nHelloWorld"
Method 2: standard mode: The end of the message is signaled by a specific character, defined in advance. This transmission mode is recommended when the sockets are used to communicate between a WINDEV application and another application. In this case, a specific character must be included in the message to indicate that the message is over.
The message has the following format: "Hello World<EOF>"
Method 3: standard mode with buffer: Corresponds to the standard mode optimized for the most frequently used protocols on Internet.
This page is also available for…