                         # just giving it as a callback directly so
                         # that it gets bound to the correct
                         # `this`.
-                        @socket.onmessage = (e) => @_data(new Buffer(new Uint8Array(e.data)))
+                        @socket.onmessage = (e) =>
+                          if e.data != 'pong'
+                            @_data(new Buffer(new Uint8Array(e.data)))
+
+                        if ping_interval > 0
+                          @ping = setInterval =>
+                            @socket.send('ping')
+                          , ping_interval
+                        else
+                          @ping = null
 
                         # Notify listeners we've connected
                         # successfully. Notably, the Connection

        # also allowed to be), then use the default protocol, which is
        # 'ws'
        protocol = if host.protocol is 'wss' then 'wss' else @DEFAULT_PROTOCOL

        # Next we construct an XHR with the path to the reql query
        # endpoint on the http server.

    # one.
    DEFAULT_PROTOCOL: 'ws'


    # We define the default ping interval in case the user doesn't specify one.
    DEFAULT_PING_INTERVAL: 37*1000

    # A static method used by `r.connect` to decide which kind of
    # connection to create in a given environment. Here we check if
    # XHRs are defined. If not, we aren't in the browser and shouldn't
