SQL Server
SQL Server
Send Encoded Bytes over a Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.SendBytesENC, which decodes text using a named encoding (such as base64) and sends the resulting binary bytes.
Background. The ENC methods move raw binary data to and from printable text using a named encoding such as
base64 or hex, which is convenient for logging or for handling binary data as strings.Chilkat SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @socket int
EXEC @hr = sp_OACreate 'Chilkat.Socket', @socket OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Connect to the server using TLS.
DECLARE @bTls int
SELECT @bTls = 1
DECLARE @maxWaitMs int
SELECT @maxWaitMs = 5000
EXEC sp_OAMethod @socket, 'Connect', @success OUT, 'example.com', 5000, @bTls, @maxWaitMs
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @socket, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @socket
RETURN
END
-- Decode the text using the named encoding, then send the resulting binary bytes. Here the base64
-- text "SGVsbG8=" decodes to the bytes for "Hello".
EXEC sp_OAMethod @socket, 'SendBytesENC', @success OUT, 'SGVsbG8=', 'base64'
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @socket, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @socket
RETURN
END
PRINT 'Bytes sent.'
EXEC @hr = sp_OADestroy @socket
END
GO