이 작업을 수행하기 위해 Celluloid's Reel by Tony Arcieri을 사용했습니다.
나는 (이 부분에 Adam Dalton에서 많은 도움을받은) 배경에서 이것을 실행
require 'reel'
CONNECTIONS = []
Reel::Server.supervise("0.0.0.0", 5000) do |connection|
while request = connection.request
case request
when Reel::Request
puts "Client requested: #{request.method} #{request.url} #{request.body}"
CONNECTIONS.each do |c|
c << request.body
end
request.respond :ok, 'YES! YOU GOT IT!'
when Reel::WebSocket
puts "Client made a WebSocket request to: #{request.url}"
CONNECTIONS << request
break
end
end
end
sleep
가 그럼 난 후 요청을 보낼 수있는 명령 줄 스크립트를 작성
my_reel.rb 릴 서버에. Writing Ruby Scripts That Respect Pipelines by Jesse Storimer에서 많은 도움을 받았습니다.
~/빈/serve_it_up
다음 #!/usr/bin/env ruby
require 'httparty'
ARGF.each_line do |line|
output_line = line.chop
HTTParty.post 'http://localhost:5000', body: output_line
end
가 작동하도록, 내 레일 응용 프로그램은 Sidekiq (bundle exec sidekiq
)를 사용하고, 출력을 보내는 버튼을 클릭 백그라운드에서 스크립트를 실행 파일로, output.txt
. 그래서 강제 꼬리를 실행하고 명령 줄 스크립트에 출력합니다. 그래서 언제 경우 output.txt 그
connection = new WebSocket('ws://localhost:5000')
connection.onmessage = (event) ->
$('#prompt').append(event.data + '<br/>')
prompt = document.getElementById('prompt')
prompt.scrollTop = prompt.scrollHeight
: 내 웹 응용 프로그램에서
tail -f output.txt | serve_it_up
, 나는 웹 소켓 사귀는하고 페이지에 출력을두고 일부 자바 스크립트 (이 경우 커피 스크립트)가 변경하면 tail -f
의 출력이 웹 브라우저에 저장됩니다. 나는 또한 #prompt
div에 제한된 높이의 스타일을 적용하고, 항상 아래쪽으로 스크롤되도록 유지합니다. #prompt {
font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;
height: 200px;
overflow: auto;
}
HUMM, 당신은이 .txt 파일에서 웹 페이지 양식 필드 값을 업데이트 하시겠습니까 : 여기
은의 스타일인가? –양식이 없습니다. 지금은 간단한 div입니다. 그리고 파일이 변경 되더라도 항상 파일의 정보를 포함하고 싶습니다. 추가 정보를 제공 할 수 있는지 알려주세요. – ardavis
오케이! 하지만 당신이 말한 웹 페이지를 업데이트하고 싶습니까? –