
---@class socket_tp_connection*
local socket_tp_connection = {}

---@class socket_tp*
---@field TIMEOUT number Default timeout.
---@type socket_tp*
local M = {}

M.TIMEOUT = 60

--- Connect to a TCP text protocol server.
---@param host string hostname.
---@param port integer port.
---@param timeout? number time out.
---@param create? function socket Create function.
---@return socket_tp_connection*? connection Connection object.
---@return string? errMsg error message.
function M.connect(host, port, timeout, create) end

--- Check the server reply code.
---@param ok string|string[]|fun(code:integer, reply:string):any Expect reply code.
---@return integer|nil code Reply code.
---@return string? reply Reply text or error.
function socket_tp_connection:check(ok) end

--- Send command.
---@param command string Order.
---@param argument? string parameter.
---@return integer|nil sent Number of bytes sent.
---@return string? errMsg error message.
function socket_tp_connection:command(command, argument) end

--- Send data.
---@param data string data.
---@return integer|nil sent Number of bytes sent.
---@return string? errMsg error message.
function socket_tp_connection:send(data) end

--- Receive data.
---@param pattern? string|integer receive mode.
---@return string|nil data data.
---@return string? errMsg error message.
function socket_tp_connection:receive(pattern) end

--- Close the connection.
---@return integer ok Returns 1 on success.
function socket_tp_connection:close() end

return M
