Class: WebSocketClient

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/helper/websocket_client.rb

Overview

A WebSocket client to help testing the WebSocket Server

Author:

  • Daniel Machado Fernandez

Version:

  • 1.0

Constant Summary

Constants included from Logging

Logging::KermitPFC

Instance Method Summary collapse

Methods included from Logging

#logger, logger

Instance Method Details

#startObject

Starts the WebSocket client to consume the published info in the WebSocket Server



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/helper/websocket_client.rb', line 13

def start

  EventMachine.run do

    puts '='*80, "Connecting to websockets server at ws://#{Settings.websocket.host}:#{Settings.websocket.port}", '='*80

    http = EventMachine::HttpRequest.new("ws://#{Settings.websocket.host}:#{Settings.websocket.port}/websocket").get :timeout => 0

    http.errback do
      logger.error "something was wrong in the websocket_client"
    end

    http.callback do
      puts "#{Time.now.strftime('%H:%M:%S')} : Connected to server"
    end

    http.stream do |msg|
      puts msg
    end

  end
  
end