Documentation ¶
Overview ¶
Package uacp provides encoding/decoding and automated connection handling for the OPC UA Connection Protocol.
To establish the connection as a client, call the Dial() function.
To wait for the client to connect to, call Listen() method, and to establish connection with the Accept() method.
Once you have a connection you can call Read() to receive full UACP messages including the header.
In uacp, *Conn also implements Local/RemoteEndpoint() methods which returns EndpointURL of client or server.
The data on top of UACP connection is passed as it is as long as the connection is established. In other words, uacp never cares the data even if it seems invalid. Users of this package should check the data to make sure it is what they want or not.
Index ¶
- Constants
- Variables
- func ResolveEndpoint(endpoint string) (network string, addr *net.TCPAddr, err error)
- type Acknowledge
- type Conn
- func (c *Conn) Close() (err error)
- func (c *Conn) Handshake(ctx context.Context, endpoint string) error
- func (c *Conn) ID() uint32
- func (c *Conn) MaxChunkCount() uint32
- func (c *Conn) MaxMessageSize() uint32
- func (c *Conn) Receive() ([]byte, error)
- func (c *Conn) ReceiveBufSize() uint32
- func (c *Conn) Send(typ string, msg interface{}) error
- func (c *Conn) SendBufSize() uint32
- func (c *Conn) SendError(code ua.StatusCode)
- type Dialer
- type Error
- type Header
- type Hello
- type Listener
- type Message
- type ReverseHello
Constants ¶
const ( KB = 1024 MB = 1024 * KB DefaultReceiveBufSize = 0xffff DefaultSendBufSize = 0xffff DefaultMaxChunkCount = 512 DefaultMaxMessageSize = 2 * MB )
const ( MessageTypeHello = "HEL" MessageTypeAcknowledge = "ACK" MessageTypeError = "ERR" MessageTypeReverseHello = "RHE" )
MessageType definitions.
Specification: Part 6, 7.1.2.2
const ( ChunkTypeIntermediate = 'C' ChunkTypeFinal = 'F' ChunkTypeAbort = 'A' )
ChunkType definitions.
Specification: Part 6, 6.7.2.2
Variables ¶
var ( // DefaultClientACK is the ACK handshake message sent to the server // for client connections. DefaultClientACK = &Acknowledge{ ReceiveBufSize: DefaultReceiveBufSize, SendBufSize: DefaultSendBufSize, MaxChunkCount: 0, MaxMessageSize: 0, } // DefaultServerACK is the ACK handshake message sent to the client // for server connections. DefaultServerACK = &Acknowledge{ ReceiveBufSize: DefaultReceiveBufSize, SendBufSize: DefaultSendBufSize, MaxChunkCount: DefaultMaxChunkCount, MaxMessageSize: DefaultMaxMessageSize, } )
Functions ¶
Types ¶
type Acknowledge ¶
type Acknowledge struct { Version uint32 ReceiveBufSize uint32 SendBufSize uint32 MaxMessageSize uint32 MaxChunkCount uint32 }
Acknowledge represents a OPC UA Acknowledge.
Specification: Part6, 7.1.2.4
func (*Acknowledge) Encode ¶
func (a *Acknowledge) Encode() ([]byte, error)
type Conn ¶
func (*Conn) MaxChunkCount ¶
func (*Conn) MaxMessageSize ¶
func (*Conn) Receive ¶
Receive reads a full UACP message from the underlying connection. The size of b must be at least ReceiveBufSize. Otherwise, the function returns an error.
func (*Conn) ReceiveBufSize ¶
func (*Conn) SendBufSize ¶
func (*Conn) SendError ¶
func (c *Conn) SendError(code ua.StatusCode)
type Dialer ¶ added in v0.2.0
type Dialer struct { // Dialer establishes the TCP connection. Defaults to net.Dialer. Dialer *net.Dialer // ClientACK defines the connection parameters requested by the client. // Defaults to DefaultClientACK. ClientACK *Acknowledge }
Dialer establishes a connection to an endpoint.
type Hello ¶
type Hello struct { Version uint32 ReceiveBufSize uint32 SendBufSize uint32 MaxMessageSize uint32 MaxChunkCount uint32 EndpointURL string }
Hello represents a OPC UA Hello.
Specification: Part6, 7.1.2.3
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener is a OPC UA Connection Protocol network listener.
func Listen ¶
func Listen(endpoint string, ack *Acknowledge) (*Listener, error)
Listen acts like net.Listen for OPC UA Connection Protocol networks.
Currently the endpoint can only be specified in "opc.tcp://<addr[:port]>/path" format.
If the IP field of laddr is nil or an unspecified IP address, Listen listens on all available unicast and anycast IP addresses of the local system. If the Port field of laddr is 0, a port number is automatically chosen.
func (*Listener) Accept ¶
Accept accepts the next incoming call and returns the new connection.
The first param ctx is to be passed to monitor(), which monitors and handles incoming messages automatically in another goroutine.
type ReverseHello ¶
ReverseHello represents a OPC UA ReverseHello.
Specification: Part6, 7.1.2.6
func (*ReverseHello) Encode ¶
func (r *ReverseHello) Encode() ([]byte, error)