It looks like the issue is not in your broadcaster server, but in your listener server.
From the Net::HTTP docs:
By default Net::HTTP reads an entire response into memory
So you need to use response.read_body and pass a block to it, instead of response.body in your listener:
response.read_body
response.body
See the docs: ruby-doc.org/stdlib-2.6.5/libdoc/n...
Hi Ely, great call on this! response.read_body is exactly what I was missing. I really appreciate you pointing me to the right place in the docs! :)
In the end, here's the listener_controller code I used:
require 'net/http' class ListenerController < ApplicationController def index url = URI.parse('http://localhost:3000/broadcaster') Net::HTTP.start(url.host, url.port) do |http| request = Net::HTTP::Get.new(url.to_s) http.request(request) do |response| puts <<-READOUT res.read_body: ============================== READOUT response.read_body do |data_str| if data_str != "" data_hash = eval(data_str.slice!(6..-1)) # slice to remove leading "data: " substring char_hash = data_hash[:character] Character.create("uuid": char_hash[:uuid], "name": char_hash[:name], "hp": char_hash[:hp], "magic": char_hash[:magic]) end end end end end end
Thank you again!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It looks like the issue is not in your broadcaster server, but in your listener server.
From the Net::HTTP docs:
So you need to use
response.read_body
and pass a block to it, instead ofresponse.body
in your listener:See the docs: ruby-doc.org/stdlib-2.6.5/libdoc/n...
Hi Ely, great call on this!
response.read_body
is exactly what I was missing. I really appreciate you pointing me to the right place in the docs! :)In the end, here's the listener_controller code I used:
Thank you again!