HTTP Client

To connect to a server over HTTP, you need to create a client object and call the connect method.

The connect method accepts these parameters:

Parameter

Description

endpointUrl

Server URL. OPC UA HTTP endpoints use opc.http://host:port/path or opc.https://host:port/path. Some servers also accept http://host:port/path or https://host:port/path.

transportProfile

Optional transport profile. If omitted, the client tries binary encoding.

Transport profile

URI

ua.TranportProfileUri.HttpsJson

http://opcfoundation.org/UA-Profile/Transport/https-json

ua.TranportProfileUri.HttpsBinary

http://opcfoundation.org/UA-Profile/Transport/https-uabinary

HTTP Examples

Binary Encoding

The following example shows how to connect to a server using binary encoding over HTTP.

local err = client:connect("opc.http://localhost:"..mako.port.."/opcua/", ua.TranportProfileUri.HttpsBinary)
if err ~= nil then
  error("connection failed: "..err)
end

trace("Connected sucessfully")

Full source

You can also omit the second parameter; the client will try to connect using binary encoding.

local err = client:connect("opc.https://localhost:"..mako.sslport.."/opcua/")
if err ~= nil then
  error("connection failed: "..err)
end

trace("Connected sucessfully")

To connect to a server over HTTPS, you need to pass URL with opc.https:// scheme.

local err = client:connect("opc.https://localhost:"..mako.sslport.."/opcua/", ua.TranportProfileUri.HttpsBinary)
if err ~= nil then
  error("connection failed: "..err)
end

trace("Connected sucessfully")

Full source

JSON Encoding

JSON encoding is a non-standard way to communicate between OPC UA clients and servers. Because of this, you can only connect to RealTimeLogic server using JSON encoding.

The following example shows how to connect to a server using JSON encoding over HTTP.

local err = client:connect("opc.https://localhost:"..mako.sslport.."/opcua/", ua.TranportProfileUri.HttpsJson)
if err ~= nil then
  error("connection failed: "..err)
end

trace("Connected sucessfully")

Full source