Lua
Lua
SSL Client Example
See more Socket/SSL/TLS Examples
Demonstrates how to connect to an SSL server, send a simple message, receive a simple response, and disconnect.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local socket = chilkat.Socket.new()
local ssl = true
local maxWaitMillisec = 20000
-- The SSL server hostname may be an IP address, a domain name,
-- or "localhost". You'll need to change this:
local sslServerHost = "123.123.88.88"
local sslServerPort = 8123
-- Connect to the SSL server:
local success = socket:connect(sslServerHost, sslServerPort, ssl, maxWaitMillisec)
if not success then
print(socket.last_error_text)
return
end
-- Set maximum timeouts for reading an writing (in millisec)
socket.max_read_idle_ms = 20000
socket.max_send_idle_ms = 20000
-- Send a "Hello Server! -EOM-" message:
success = socket:send_string("Hello Server! -EOM-")
if not success then
print(socket.last_error_text)
return
end
-- The server (in this example) is going to send a "Hello Client! -EOM-"
-- message. Read it:
local receivedMsg = socket:receive_until_match("-EOM-")
if not socket.last_method_success then
print(socket.last_error_text)
return
end
-- Close the connection with the server
-- Wait a max of 20 seconds (20000 millsec)
success = socket:close(20000)
print(receivedMsg)