Classic ASP
Classic ASP
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 Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
set socket = Server.CreateObject("Chilkat.Socket")
' Connect to the server using TLS.
bTls = 1
maxWaitMs = 5000
success = socket.Connect("example.com",5000,bTls,maxWaitMs)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( socket.LastErrorText) & "</pre>"
Response.End
End If
' 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.
messageLength = 512
success = socket.SendCount(messageLength)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( socket.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Length prefix sent.") & "</pre>"
%>
</body>
</html>