diff --git a/src/libnmdc/libnmdc.go b/src/libnmdc/libnmdc.go index 554e612..e403f15 100644 --- a/src/libnmdc/libnmdc.go +++ b/src/libnmdc/libnmdc.go @@ -342,10 +342,14 @@ func (this *HubConnection) worker() { } if err != nil { - this.OnEvent <- HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_CONNECTING} + this.State = CONNECTIONSTATE_DISCONNECTED this.connValid = false + } else { + this.State = CONNECTIONSTATE_CONNECTING this.connValid = true + this.OnEvent <- HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_CONNECTING} + } } @@ -361,7 +365,10 @@ func (this *HubConnection) worker() { // Maybe we disconnected if err != nil { this.OnEvent <- HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_DISCONNECTED, Message: err.Error()} + this.State = CONNECTIONSTATE_DISCONNECTED this.conn = nil + this.connValid = false + time.Sleep(30 * time.Second) // Wait before reconnect continue }