         _this.$ws.on('close', ->)
         _this.$ws.on('error', ->)
       
-      error_cb = (msg) -> ->
-        debug msg
+      error_cb = (msg) -> (e) ->
         clear_state()
-        except_cb -> rs.java_throw rs.get_bs_class('Ljava/io/IOException;'), msg
+        except_cb -> rs.java_throw rs.get_bs_class('Ljava/io/IOException;'), msg + ": " + e
+          
+      close_cb = (msg) -> (e) ->
+        clear_state()
+        except_cb -> rs.java_throw rs.get_bs_class('Ljava/io/IOException;'), msg + ": " + websocket_status_to_message(e.status)
       
       # Success case
       _this.$ws.on('open', ->

        resume_cb())
      
      # Error cases
      _this.$ws.on('close', error_cb('Connection failed! (Closed)'))
      _this.$ws.on('error', error_cb('Connection failed! (Error)'))
      
      # Timeout case
      id = window.setTimeout(error_cb('Connection timeout!'), timeout) if timeout > 0

      try
        _this.$ws.open host
      catch err
        error_cb('Connection failed! (exception)')(err.message)
      
      
  o 'socketBind(Ljava/net/InetAddress;I)V', (rs, _this, address, port) ->
