    
   ##-----------------------------------------
 
+  handle_error : (e) ->
+    @_warn e
+    @close()
+    @_reconnect()
+   
+  ##-----------------------------------------
+
   handle_close : () ->
-    # noop for now, maybe do something clever in subclasses
+    @tcp_stream = null if @tcp_stream
+    @_reconnect()
    
+  ##-----------------------------------------
+
+  reconnect : () ->
+    throw new Error "Reconnect called when @tcp_stream != null" if @tcp_stream
+    if @reconnect_delay?
+      await setTimeout defer(), @reconnect_delay
+      @_warn "reconnecting..."
+      @connect()
+ 
   ##-----------------------------------------
   
   activate_stream : () ->

  ##-----------------------------------------

  constructor : ({ @port, @host, @tcp_opts, @tcp_stream, @log_hook,
                   @parent, @do_tcp_delay}) ->
    super
    
    @host = "localhost" if not @host or @host is "-"

    else
      res = true
    @_lock.release()
    cb res if cb

  ##-----------------------------------------

