Lua
Lua
Send Bytes on a Socket Connection
See more Socket/SSL/TLS Examples
Demonstrates how to send a mixture of binary (non-text) and text bytes on a socket connection.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local socket = chilkat.Socket.new()
-- Connect to some host:port
local ssl = false
local maxWaitMillisec = 20000
local port = 5555
local success = socket:connect("test.com", port, ssl, maxWaitMillisec)
if not success then
print(socket.last_error_text)
return
end
-- We wish to send a 0x00 byte followed by the us-ascii string "10800"
local bd = chilkat.BinData.new()
bd:append_byte(0)
bd:append_string("10800", "utf-8")
-- Send the entire contents of bd.
success = socket:send_bd(bd, 0, 0)
if not success then
print(socket.last_error_text)
return
end