def on_handshake_complete

      @decoder.onping do |data|
        @socket.send_data @encoder.pong(data)
        emit :ping, data
      end

      @decoder.onpong do |data|
        emit :pong, data
      end

      @decoder.onclose do |code|
        close code
      end

      @decoder.onframe do |frame, binary|
        emit :frame, frame, binary
      end

      @decoder.onerror do |code, message|
        close code, message
        emit :error, code, message
      end

      emit :open

      if @handshake.extra
       receive_message_data @handshake.extra
      end
    end
def on_handshake_complete

      @decoder.onping do |data|
        @socket.send_data @encoder.pong(data)
        emit :ping, data
      end

      @decoder.onpong do |data|
        emit :pong, data
      end

      @decoder.onclose do |code|
        close code
      end

      @decoder.onframe do |frame, binary|
        emit :frame, frame, binary
      end

      @decoder.onerror do |code, message|
        close code, message
        emit :error, code, message
      end

      emit :open

      if @handshake.extra
       receive_message_data @handshake.extra
      end
    end
Internal: setup encoder/decoder and bind
 to all decoder events.