sample/stream.rb
raw| 1 | $:.unshift(File.join('..', 'lib')) |
| 2 | require "httpclient" |
| 3 | |
| 4 | c = HTTPClient.new |
| 5 | |
| 6 | piper, pipew = IO.pipe |
| 7 | conn = c.post_async("http://localhost:8080/stream", piper) |
| 8 | |
| 9 | Thread.new do |
| 10 | res = conn.pop |
| 11 | while str = res.content.read(10) |
| 12 | p str |
| 13 | end |
| 14 | end |
| 15 | |
| 16 | p "type here" |
| 17 | while line = STDIN.gets |
| 18 | pipew << line |
| 19 | end |
| 20 | pipew.close |
| 21 | sleep 5 |