From 522550d804bd460c79750d0b06cb15565bdec44b Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 29 Apr 2019 12:19:18 +0300 Subject: [PATCH 01/12] Publish --- client.go | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/client.go b/client.go index 12ced856..b19a34a7 100644 --- a/client.go +++ b/client.go @@ -7,6 +7,7 @@ package opcua import ( "context" "crypto/rand" + "errors" "fmt" "log" "sync" @@ -426,3 +427,108 @@ func (c *Client) Subscribe(intv time.Duration) (*Subscription, error) { }) return &Subscription{res}, err } + +type PublishResponse struct { + Error error + DataChangeNotification *ua.DataChangeNotification + EventNotificationList *ua.EventNotificationList + StatusChangeNotification *ua.StatusChangeNotification +} + +func (c *Client) Publish(dataChan chan<- PublishResponse) { + var ( + subAck = make([]*ua.SubscriptionAcknowledgement, 0) + pubRequest = &ua.PublishRequest{} + pubResponse *ua.PublishResponse + responseError ua.StatusCode + err error + ) + for { + // Empty SubscriptionAcknowledgements for first PublishRequest + pubRequest.SubscriptionAcknowledgements = subAck + + // PublishRequest + err = c.Send(pubRequest, func(v interface{}) error { + r, ok := v.(*ua.PublishResponse) + if !ok { + return fmt.Errorf("invalid response: %T", v) + } + pubResponse = r + return nil + }) + if err != nil { + dataChan <- PublishResponse{ + Error: err, + } + continue + } + + // Check for errors + responseError = ua.StatusOK + for _, result := range pubResponse.Results { + if result != ua.StatusOK { + responseError = result + break + } + } + if responseError != ua.StatusOK { + dataChan <- PublishResponse{ + Error: fmt.Errorf("publish response error: %v", responseError), + } + continue + } + + // Prepare SubscriptionAcknowledgement for next PublishRequest + subAck = make([]*ua.SubscriptionAcknowledgement, 0) + for _, number := range pubResponse.AvailableSequenceNumbers { + subAck = append(subAck, &ua.SubscriptionAcknowledgement{ + SubscriptionID: pubResponse.SubscriptionID, + SequenceNumber: number, + }) + } + + if pubResponse.NotificationMessage == nil { + dataChan <- PublishResponse{ + Error: errors.New("empty NotificationMessage"), + } + continue + } + + // Part 4, 7.21 NotificationMessage + for _, data := range pubResponse.NotificationMessage.NotificationData { + // Part 4, 7.20 NotificationData parameters + if data == nil { + dataChan <- PublishResponse{ + Error: fmt.Errorf("NotificationData parameter is nil"), + } + continue + } + + switch data.Value.(type) { + // Part 4, 7.20.2 DataChangeNotification parameter + case *ua.DataChangeNotification: + dataChan <- PublishResponse{ + DataChangeNotification: data.Value.(*ua.DataChangeNotification), + } + + // Part 4, 7.20.3 EventNotificationList parameter + case *ua.EventNotificationList: + dataChan <- PublishResponse{ + EventNotificationList: data.Value.(*ua.EventNotificationList), + } + + // Part 4, 7.20.4 StatusChangeNotification parameter + case *ua.StatusChangeNotification: + dataChan <- PublishResponse{ + StatusChangeNotification: data.Value.(*ua.StatusChangeNotification), + } + + // Error + default: + dataChan <- PublishResponse{ + Error: fmt.Errorf("unknown NotificationData parameter: %v", data.Value), + } + } + } + } +} From 7f2a3b08630af115e28d431e3b3aa533b0903ae1 Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 29 Apr 2019 12:25:40 +0300 Subject: [PATCH 02/12] Publish --- client.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index b19a34a7..9d84cf7c 100644 --- a/client.go +++ b/client.go @@ -428,14 +428,14 @@ func (c *Client) Subscribe(intv time.Duration) (*Subscription, error) { return &Subscription{res}, err } -type PublishResponse struct { +type PublishNotificationData struct { Error error DataChangeNotification *ua.DataChangeNotification EventNotificationList *ua.EventNotificationList StatusChangeNotification *ua.StatusChangeNotification } -func (c *Client) Publish(dataChan chan<- PublishResponse) { +func (c *Client) Publish(dataChan chan<- PublishNotificationData) { var ( subAck = make([]*ua.SubscriptionAcknowledgement, 0) pubRequest = &ua.PublishRequest{} @@ -457,7 +457,7 @@ func (c *Client) Publish(dataChan chan<- PublishResponse) { return nil }) if err != nil { - dataChan <- PublishResponse{ + dataChan <- PublishNotificationData{ Error: err, } continue @@ -472,7 +472,7 @@ func (c *Client) Publish(dataChan chan<- PublishResponse) { } } if responseError != ua.StatusOK { - dataChan <- PublishResponse{ + dataChan <- PublishNotificationData{ Error: fmt.Errorf("publish response error: %v", responseError), } continue @@ -488,7 +488,7 @@ func (c *Client) Publish(dataChan chan<- PublishResponse) { } if pubResponse.NotificationMessage == nil { - dataChan <- PublishResponse{ + dataChan <- PublishNotificationData{ Error: errors.New("empty NotificationMessage"), } continue @@ -498,7 +498,7 @@ func (c *Client) Publish(dataChan chan<- PublishResponse) { for _, data := range pubResponse.NotificationMessage.NotificationData { // Part 4, 7.20 NotificationData parameters if data == nil { - dataChan <- PublishResponse{ + dataChan <- PublishNotificationData{ Error: fmt.Errorf("NotificationData parameter is nil"), } continue @@ -507,25 +507,25 @@ func (c *Client) Publish(dataChan chan<- PublishResponse) { switch data.Value.(type) { // Part 4, 7.20.2 DataChangeNotification parameter case *ua.DataChangeNotification: - dataChan <- PublishResponse{ + dataChan <- PublishNotificationData{ DataChangeNotification: data.Value.(*ua.DataChangeNotification), } // Part 4, 7.20.3 EventNotificationList parameter case *ua.EventNotificationList: - dataChan <- PublishResponse{ + dataChan <- PublishNotificationData{ EventNotificationList: data.Value.(*ua.EventNotificationList), } // Part 4, 7.20.4 StatusChangeNotification parameter case *ua.StatusChangeNotification: - dataChan <- PublishResponse{ + dataChan <- PublishNotificationData{ StatusChangeNotification: data.Value.(*ua.StatusChangeNotification), } // Error default: - dataChan <- PublishResponse{ + dataChan <- PublishNotificationData{ Error: fmt.Errorf("unknown NotificationData parameter: %v", data.Value), } } From 77f3dc4beebd9f978b4a2d7e7f4375a38686ec8a Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 29 Apr 2019 12:51:10 +0300 Subject: [PATCH 03/12] Publish --- client.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index 9d84cf7c..d954b29a 100644 --- a/client.go +++ b/client.go @@ -430,6 +430,7 @@ func (c *Client) Subscribe(intv time.Duration) (*Subscription, error) { type PublishNotificationData struct { Error error + SubscriptionID uint32 DataChangeNotification *ua.DataChangeNotification EventNotificationList *ua.EventNotificationList StatusChangeNotification *ua.StatusChangeNotification @@ -453,6 +454,7 @@ func (c *Client) Publish(dataChan chan<- PublishNotificationData) { if !ok { return fmt.Errorf("invalid response: %T", v) } + pubResponse = r return nil }) @@ -473,7 +475,8 @@ func (c *Client) Publish(dataChan chan<- PublishNotificationData) { } if responseError != ua.StatusOK { dataChan <- PublishNotificationData{ - Error: fmt.Errorf("publish response error: %v", responseError), + Error: fmt.Errorf("publish response error: %v", responseError), + SubscriptionID: pubResponse.SubscriptionID, } continue } @@ -489,7 +492,8 @@ func (c *Client) Publish(dataChan chan<- PublishNotificationData) { if pubResponse.NotificationMessage == nil { dataChan <- PublishNotificationData{ - Error: errors.New("empty NotificationMessage"), + Error: errors.New("empty NotificationMessage"), + SubscriptionID: pubResponse.SubscriptionID, } continue } @@ -499,7 +503,8 @@ func (c *Client) Publish(dataChan chan<- PublishNotificationData) { // Part 4, 7.20 NotificationData parameters if data == nil { dataChan <- PublishNotificationData{ - Error: fmt.Errorf("NotificationData parameter is nil"), + Error: fmt.Errorf("NotificationData parameter is nil"), + SubscriptionID: pubResponse.SubscriptionID, } continue } @@ -509,24 +514,28 @@ func (c *Client) Publish(dataChan chan<- PublishNotificationData) { case *ua.DataChangeNotification: dataChan <- PublishNotificationData{ DataChangeNotification: data.Value.(*ua.DataChangeNotification), + SubscriptionID: pubResponse.SubscriptionID, } // Part 4, 7.20.3 EventNotificationList parameter case *ua.EventNotificationList: dataChan <- PublishNotificationData{ EventNotificationList: data.Value.(*ua.EventNotificationList), + SubscriptionID: pubResponse.SubscriptionID, } // Part 4, 7.20.4 StatusChangeNotification parameter case *ua.StatusChangeNotification: dataChan <- PublishNotificationData{ StatusChangeNotification: data.Value.(*ua.StatusChangeNotification), + SubscriptionID: pubResponse.SubscriptionID, } // Error default: dataChan <- PublishNotificationData{ - Error: fmt.Errorf("unknown NotificationData parameter: %v", data.Value), + Error: fmt.Errorf("unknown NotificationData parameter: %v", data.Value), + SubscriptionID: pubResponse.SubscriptionID, } } } From 0b0f415e5c741f7733c3147ffe82a20a8debd2c7 Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 29 Apr 2019 13:09:52 +0300 Subject: [PATCH 04/12] Publish --- examples/publish/publish.go | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 examples/publish/publish.go diff --git a/examples/publish/publish.go b/examples/publish/publish.go new file mode 100644 index 00000000..55ea8ae3 --- /dev/null +++ b/examples/publish/publish.go @@ -0,0 +1,51 @@ +// Copyright 2018-2019 opcua authors. All rights reserved. +// Use of this source code is governed by a MIT-style license that can be +// found in the LICENSE file. + +package main + +import ( + "flag" + "log" + "time" + + "github.com/gopcua/opcua" + "github.com/gopcua/opcua/debug" +) + +func main() { + endpoint := flag.String("endpoint", "opc.tcp://localhost:4840", "OPC UA Endpoint URL") + flag.BoolVar(&debug.Enable, "debug", false, "enable debug logging") + flag.Parse() + log.SetFlags(0) + + c := opcua.NewClient(*endpoint) + if err := c.Connect(); err != nil { + log.Fatal(err) + } + defer func() { + _ = c.Close() + }() + + var ch = make(chan opcua.PublishNotificationData) + go c.Publish(ch) + + for { + var response = <-ch + + var t = time.Now().Format(time.RFC3339) + if response.Error != nil { + log.Printf("%s - %s \n", t, response.Error.Error()) + continue + } + + if response.DataChangeNotification != nil { + for _, item := range response.DataChangeNotification.MonitoredItems { + var data, ok = item.Value.Value.Value.(float64) + if ok { + log.Printf("%s - %g \n", t, data) + } + } + } + } +} From f3f3d99bd6721024bf80e939912ebcf0c38e4892 Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 29 Apr 2019 13:13:34 +0300 Subject: [PATCH 05/12] Publish --- examples/publish/publish.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/publish/publish.go b/examples/publish/publish.go index 55ea8ae3..7ef075c6 100644 --- a/examples/publish/publish.go +++ b/examples/publish/publish.go @@ -23,11 +23,9 @@ func main() { if err := c.Connect(); err != nil { log.Fatal(err) } - defer func() { - _ = c.Close() - }() + c.Close() - var ch = make(chan opcua.PublishNotificationData) + ch := make(chan opcua.PublishNotificationData) go c.Publish(ch) for { From 82835620a557cabb160c62954aa5c7f53ea1d0b5 Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 29 Apr 2019 13:14:25 +0300 Subject: [PATCH 06/12] Publish --- examples/publish/publish.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/publish/publish.go b/examples/publish/publish.go index 7ef075c6..bfaab36b 100644 --- a/examples/publish/publish.go +++ b/examples/publish/publish.go @@ -23,7 +23,7 @@ func main() { if err := c.Connect(); err != nil { log.Fatal(err) } - c.Close() + defer c.Close() ch := make(chan opcua.PublishNotificationData) go c.Publish(ch) From db1604a0ac653f670892194997c23d072cea9ccd Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 29 Apr 2019 13:17:59 +0300 Subject: [PATCH 07/12] Publish --- examples/publish/publish.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/publish/publish.go b/examples/publish/publish.go index bfaab36b..0bb7e159 100644 --- a/examples/publish/publish.go +++ b/examples/publish/publish.go @@ -33,7 +33,7 @@ func main() { var t = time.Now().Format(time.RFC3339) if response.Error != nil { - log.Printf("%s - %s \n", t, response.Error.Error()) + log.Printf("%s - %v \n", t, response.Error) continue } From 9a1bcb79044589c6bd9e10d8cd0e54ef6773bbbd Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 29 Apr 2019 13:24:33 +0300 Subject: [PATCH 08/12] Publish --- examples/publish/publish.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/publish/publish.go b/examples/publish/publish.go index 0bb7e159..22c29dd9 100644 --- a/examples/publish/publish.go +++ b/examples/publish/publish.go @@ -29,19 +29,19 @@ func main() { go c.Publish(ch) for { - var response = <-ch + var resp = <-ch var t = time.Now().Format(time.RFC3339) - if response.Error != nil { - log.Printf("%s - %v \n", t, response.Error) + if resp.Error != nil { + log.Printf("%s - %v", t, resp.Error) continue } - if response.DataChangeNotification != nil { - for _, item := range response.DataChangeNotification.MonitoredItems { + if resp.DataChangeNotification != nil { + for _, item := range resp.DataChangeNotification.MonitoredItems { var data, ok = item.Value.Value.Value.(float64) if ok { - log.Printf("%s - %g \n", t, data) + log.Printf("%s - %g", t, data) } } } From 3074f5a48959e34596aaf2c4231ba20a8195e1db Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 29 Apr 2019 14:02:32 +0300 Subject: [PATCH 09/12] Publish --- examples/publish/publish.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/publish/publish.go b/examples/publish/publish.go index 22c29dd9..14bfb4be 100644 --- a/examples/publish/publish.go +++ b/examples/publish/publish.go @@ -29,9 +29,9 @@ func main() { go c.Publish(ch) for { - var resp = <-ch + resp := <-ch - var t = time.Now().Format(time.RFC3339) + t := time.Now().Format(time.RFC3339) if resp.Error != nil { log.Printf("%s - %v", t, resp.Error) continue @@ -39,7 +39,7 @@ func main() { if resp.DataChangeNotification != nil { for _, item := range resp.DataChangeNotification.MonitoredItems { - var data, ok = item.Value.Value.Value.(float64) + data, ok := item.Value.Value.Value.(float64) if ok { log.Printf("%s - %g", t, data) } From fd9cd173d30dc2c13b7efc65c132358f3ae594b0 Mon Sep 17 00:00:00 2001 From: Eugene Denisenko Date: Mon, 29 Apr 2019 14:03:52 +0300 Subject: [PATCH 10/12] Publish --- examples/publish/publish.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/publish/publish.go b/examples/publish/publish.go index 14bfb4be..9c59c85c 100644 --- a/examples/publish/publish.go +++ b/examples/publish/publish.go @@ -7,7 +7,6 @@ package main import ( "flag" "log" - "time" "github.com/gopcua/opcua" "github.com/gopcua/opcua/debug" @@ -30,10 +29,8 @@ func main() { for { resp := <-ch - - t := time.Now().Format(time.RFC3339) if resp.Error != nil { - log.Printf("%s - %v", t, resp.Error) + log.Printf("%v", resp.Error) continue } @@ -41,7 +38,7 @@ func main() { for _, item := range resp.DataChangeNotification.MonitoredItems { data, ok := item.Value.Value.Value.(float64) if ok { - log.Printf("%s - %g", t, data) + log.Printf("%g", data) } } } From e846a90370c072807f2e6a562df2dc6a624ea968 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Mon, 29 Apr 2019 17:07:53 +0200 Subject: [PATCH 11/12] cleanup --- client.go | 109 +++++++++++++++--------------------- examples/publish/publish.go | 12 ++-- 2 files changed, 52 insertions(+), 69 deletions(-) diff --git a/client.go b/client.go index d954b29a..f44ac5e9 100644 --- a/client.go +++ b/client.go @@ -7,7 +7,6 @@ package opcua import ( "context" "crypto/rand" - "errors" "fmt" "log" "sync" @@ -429,113 +428,95 @@ func (c *Client) Subscribe(intv time.Duration) (*Subscription, error) { } type PublishNotificationData struct { - Error error - SubscriptionID uint32 - DataChangeNotification *ua.DataChangeNotification - EventNotificationList *ua.EventNotificationList - StatusChangeNotification *ua.StatusChangeNotification + SubscriptionID uint32 + Error error + Value interface{} } -func (c *Client) Publish(dataChan chan<- PublishNotificationData) { - var ( - subAck = make([]*ua.SubscriptionAcknowledgement, 0) - pubRequest = &ua.PublishRequest{} - pubResponse *ua.PublishResponse - responseError ua.StatusCode - err error - ) +func (c *Client) Publish(notif chan<- PublishNotificationData) { for { // Empty SubscriptionAcknowledgements for first PublishRequest - pubRequest.SubscriptionAcknowledgements = subAck + req := &ua.PublishRequest{ + SubscriptionAcknowledgements: []*ua.SubscriptionAcknowledgement{}, + } - // PublishRequest - err = c.Send(pubRequest, func(v interface{}) error { + var res *ua.PublishResponse + err := c.Send(req, func(v interface{}) error { r, ok := v.(*ua.PublishResponse) if !ok { return fmt.Errorf("invalid response: %T", v) } - - pubResponse = r + res = r return nil }) if err != nil { - dataChan <- PublishNotificationData{ - Error: err, - } + notif <- PublishNotificationData{Error: err} continue } // Check for errors - responseError = ua.StatusOK - for _, result := range pubResponse.Results { - if result != ua.StatusOK { - responseError = result + status := ua.StatusOK + for _, res := range res.Results { + if res != ua.StatusOK { + status = res break } } - if responseError != ua.StatusOK { - dataChan <- PublishNotificationData{ - Error: fmt.Errorf("publish response error: %v", responseError), - SubscriptionID: pubResponse.SubscriptionID, + + if status != ua.StatusOK { + notif <- PublishNotificationData{ + SubscriptionID: res.SubscriptionID, + Error: status, } continue } // Prepare SubscriptionAcknowledgement for next PublishRequest - subAck = make([]*ua.SubscriptionAcknowledgement, 0) - for _, number := range pubResponse.AvailableSequenceNumbers { - subAck = append(subAck, &ua.SubscriptionAcknowledgement{ - SubscriptionID: pubResponse.SubscriptionID, - SequenceNumber: number, - }) + var acks []*ua.SubscriptionAcknowledgement + for _, i := range res.AvailableSequenceNumbers { + ack := &ua.SubscriptionAcknowledgement{ + SubscriptionID: res.SubscriptionID, + SequenceNumber: i, + } + acks = append(acks, ack) } - if pubResponse.NotificationMessage == nil { - dataChan <- PublishNotificationData{ - Error: errors.New("empty NotificationMessage"), - SubscriptionID: pubResponse.SubscriptionID, + if res.NotificationMessage == nil { + notif <- PublishNotificationData{ + SubscriptionID: res.SubscriptionID, + Error: fmt.Errorf("empty NotificationMessage"), } continue } // Part 4, 7.21 NotificationMessage - for _, data := range pubResponse.NotificationMessage.NotificationData { + for _, data := range res.NotificationMessage.NotificationData { // Part 4, 7.20 NotificationData parameters - if data == nil { - dataChan <- PublishNotificationData{ - Error: fmt.Errorf("NotificationData parameter is nil"), - SubscriptionID: pubResponse.SubscriptionID, + if data == nil || data.Value == nil { + notif <- PublishNotificationData{ + SubscriptionID: res.SubscriptionID, + Error: fmt.Errorf("missing NotificationData parameter"), } continue } switch data.Value.(type) { // Part 4, 7.20.2 DataChangeNotification parameter - case *ua.DataChangeNotification: - dataChan <- PublishNotificationData{ - DataChangeNotification: data.Value.(*ua.DataChangeNotification), - SubscriptionID: pubResponse.SubscriptionID, - } - // Part 4, 7.20.3 EventNotificationList parameter - case *ua.EventNotificationList: - dataChan <- PublishNotificationData{ - EventNotificationList: data.Value.(*ua.EventNotificationList), - SubscriptionID: pubResponse.SubscriptionID, - } - // Part 4, 7.20.4 StatusChangeNotification parameter - case *ua.StatusChangeNotification: - dataChan <- PublishNotificationData{ - StatusChangeNotification: data.Value.(*ua.StatusChangeNotification), - SubscriptionID: pubResponse.SubscriptionID, + case *ua.DataChangeNotification, + *ua.EventNotificationList, + *ua.StatusChangeNotification: + notif <- PublishNotificationData{ + SubscriptionID: res.SubscriptionID, + Value: data.Value, } // Error default: - dataChan <- PublishNotificationData{ - Error: fmt.Errorf("unknown NotificationData parameter: %v", data.Value), - SubscriptionID: pubResponse.SubscriptionID, + notif <- PublishNotificationData{ + SubscriptionID: res.SubscriptionID, + Error: fmt.Errorf("unknown NotificationData parameter: %T", data.Value), } } } diff --git a/examples/publish/publish.go b/examples/publish/publish.go index 9c59c85c..f8bf9e2e 100644 --- a/examples/publish/publish.go +++ b/examples/publish/publish.go @@ -10,6 +10,7 @@ import ( "github.com/gopcua/opcua" "github.com/gopcua/opcua/debug" + "github.com/gopcua/opcua/ua" ) func main() { @@ -28,14 +29,15 @@ func main() { go c.Publish(ch) for { - resp := <-ch - if resp.Error != nil { - log.Printf("%v", resp.Error) + res := <-ch + if res.Error != nil { + log.Print(res.Error) continue } - if resp.DataChangeNotification != nil { - for _, item := range resp.DataChangeNotification.MonitoredItems { + switch x := res.Value.(type) { + case *ua.DataChangeNotification: + for _, item := range x.MonitoredItems { data, ok := item.Value.Value.Value.(float64) if ok { log.Printf("%g", data) From 1ecf3e578b69f89f28b23bb20d92e5136f9d8322 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Mon, 29 Apr 2019 17:14:25 +0200 Subject: [PATCH 12/12] fix acks --- client.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index f44ac5e9..3fad6841 100644 --- a/client.go +++ b/client.go @@ -434,10 +434,12 @@ type PublishNotificationData struct { } func (c *Client) Publish(notif chan<- PublishNotificationData) { + // Empty SubscriptionAcknowledgements for first PublishRequest + var acks = make([]*ua.SubscriptionAcknowledgement, 0) + for { - // Empty SubscriptionAcknowledgements for first PublishRequest req := &ua.PublishRequest{ - SubscriptionAcknowledgements: []*ua.SubscriptionAcknowledgement{}, + SubscriptionAcknowledgements: acks, } var res *ua.PublishResponse @@ -472,7 +474,7 @@ func (c *Client) Publish(notif chan<- PublishNotificationData) { } // Prepare SubscriptionAcknowledgement for next PublishRequest - var acks []*ua.SubscriptionAcknowledgement + acks = make([]*ua.SubscriptionAcknowledgement, 0) for _, i := range res.AvailableSequenceNumbers { ack := &ua.SubscriptionAcknowledgement{ SubscriptionID: res.SubscriptionID,