Changes the transmission mode used on a socket. This feature is used to define the message encoding during the transmission. SocketRead
are using the specified transmission mode.
Caution: The transmission mode must be identical on the server and on the client computer.
- UDP sockets: The UDP sockets are always "Socket without tag". SocketChangeTransmissionMode must not be used with the UDP sockets. The UDP protocol is an unreliable protocol: the string returned by SocketWrite may not arrive or it may arrive several times. The strings are not always sent in order.
: A socket is a communication resource used by the applications to communicate between computers regardless of the network type.
// Implement the transmission mode with EOF as end marker
IF SocketChangeTransmissionMode("Server", SocketEndTag) = True THEN
Info("Transmission mode modified")
// Implement the transmission mode with CRLF as end marker
IF SocketChangeTransmissionMode(sSocketname, SocketEndTag, CRLF) = False THEN
<Result> = SocketChangeTransmissionMode(<Socket Name> , <Type of Transmission> [, <Option>])
- True if the function was successful,
- False otherwise (invalid socket name for example). To find out the error details, use ErrorInfo.
<Socket Name>: Character string (with quotes)
Name of socket defined on the server. This name was defined:
<Type of Transmission>: Constant
Type of transmission to use:
|This message is a buffer in the following format: |
<Length>+CR+<String or buffer to send>
<Length> is an ANSI string corresponding to the length of the string or buffer in bytes.
|SocketEndTag||Used to specify an end tag in <Option>. By default, the end tag is the "<EOF>" character string. |
Message in the following format: "Hello world<EOF>"
|SocketEndTagBuffer||Used to specify a buffer end tag in <Option>. By default, the end tag of buffer is the "<EOF>" string. Check remarks to see the difference with the SocketEndTag constant.|
|SocketNoEndTag||No tag is added to and/or removed from the transmitted string. In this case, the maximum number of bytes that can be transmitted can be specified with SocketRead.|
<Option>: Optional character string (with quotes) or WLanguage constant (CR, CRLF, EOT)
End tag (by default, this marker is the "<EOF>" string).
Type of message transmission
The type of message transmission specifies the mode used to define the length of the message.
By default (SocketSizeAtBeginning constant), the number of characters in the message is specified at the beginning of the message. This transmission mode is recommended when the sockets are used to communicate between two WINDEV applications.
The SocketEndTag and SocketEndTagBuffer constants allow you to use the standard mode for defining the length of messages when communicating by sockets. 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.
Differences of operating mode between the SocketEndTag and SocketEndTagBuffer constants
In both cases, the read operation on the socket waits to receive the end tag.
- With the SocketEndTag constant: A WLanguage error occurs ("End markers not respected") if elements are received after the end marker.
- With the SocketEndTagBuffer constant: If elements are received after the end marker, the received string is read until the end marker is reached, the remaining part is stored and carried over into the next read operation. This allows you to perform partial read operations. This mode simplifies the process of some standard protocols on Internet.
For example: when connecting to a news server (NNTP protocol), the protocol indicates that the end tag can be "<CRLF>" or "<CRLF>.<CRLF>". With the "buffered" mode, you can read the first line, and wait for the second tag only if one is expected.
If the encoding of the message takes the end tag into account, there is no need to specify it in the message.
Transmission between two computers that use character strings in different formats (UNICODE and ANSI)
Some conversions may be required (AnsiToUnicode
) when messages are transmitted between two computers that use character strings in different formats.