require 'socket'     

hostname = 'localhost'
port = 8992
data = '{"type":"SUBSCRIBE"}'


socket = TCPSocket.open(hostname, port)
puts "Connected #{hostname}:#{port}"

socket.puts(data)
complete_json = false
open=0
return_data=""

def processMessage(msg)
	puts msg
    #Process the feed messages here
end

loop do   # Read lines from the socket
   check_bracket = socket.recv(1)
   return_data.concat(check_bracket)
   next unless check_bracket.include? "{" or check_bracket.include?"}"
   open += 1 if check_bracket.include?"{"
   open -= 1 if check_bracket.include?"}"  
   next unless open == 0	
   processMessage return_data
   return_data = ""  
end
socket.close     # Close the socket when done