AutoIt
AutoIt
Send a 4-byte Length Prefix over a Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.SendCount, which sends a four-byte length prefix in network byte order. This is typically used to tell the peer how many bytes follow.
Background. A length-prefixed framing scheme sends the byte count of a message before the message body, so the receiver knows exactly how many bytes to read with a counted receive.
Chilkat AutoIt Downloads
Local $bSuccess = False
$oSocket = ObjCreate("Chilkat.Socket")
; Connect to the server using TLS.
Local $bTls = True
Local $iMaxWaitMs = 5000
$bSuccess = $oSocket.Connect("example.com",5000,$bTls,$iMaxWaitMs)
If ($bSuccess = False) Then
ConsoleWrite($oSocket.LastErrorText & @CRLF)
Exit
EndIf
; Send a four-byte length prefix in network byte order. A common framing pattern is to send the
; number of bytes in a message before the message itself, so the peer knows exactly how many bytes
; to read.
Local $iMessageLength = 512
$bSuccess = $oSocket.SendCount($iMessageLength)
If ($bSuccess = False) Then
ConsoleWrite($oSocket.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Length prefix sent." & @CRLF)