     @makeClient()
 
   reconnect: () ->
-    console.log 'reconnect'
+    @reconnectTryCount += 1
+    if @reconnectTryCount > 5
+      @robot.logger.error 'Unable to reconnect to UppTalk server.'
+      process.exit 1
+
+    setTimeout () =>
+      @robot.logger.info 'Hubot UppTalk reconnecting.'
+      @client.open()
+    , 5000
 
   makeClient: () ->
     options = @options


  constructor: ( robot ) ->
    @robot = robot

  run: ->
    options =

      return
    if !p.text
      return
    # ignore offline messages
    if p.timestamp
      return

    @robot.logger.debug "Received message: #{p.text} from: #{p.user}"

    user = @robot.brain.userForId p.user
    user.name = p.name or p.user

    if p.group
      user.room = p.group
    else
      delete user.room
      #hack to avoid having to prepand commands with hubot name
      if p.text.toLowerCase().indexOf @robot.name.toLowerCase() != 0
        p.text = 'hubot ' + p.text

    @receive new TextMessage(user, p.text, p.id)

