SQL Server
SQL Server
Send a 32-bit Integer over a Socket
See more Socket/SSL/TLS Examples
Demonstrates Socket.SendInt32, which sends a value as a four-byte signed integer in the selected byte order.
Background. Fixed-size integers and length prefixes are common building blocks for application-defined binary protocols. Byte order is selectable, with big-endian being network byte order.
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
-- Send the value as a four-byte signed integer. Use 1 for network byte order (big-endian) or
-- 0 for little-endian.
DECLARE @bBigEndian int
SELECT @bBigEndian = 1
EXEC sp_OAMethod @socket, 'SendInt32', @success OUT, 1000000, @bBigEndian
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @socket, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @socket
RETURN
END
PRINT '32-bit integer sent.'
EXEC @hr = sp_OADestroy @socket
END
GO