程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> java中完成兼容ie6 7 8 9的spring4+websocket

java中完成兼容ie6 7 8 9的spring4+websocket

編輯:關於JAVA

java中完成兼容ie6 7 8 9的spring4+websocket。本站提示廣大學習愛好者:(java中完成兼容ie6 7 8 9的spring4+websocket)文章只能為提供參考,不一定能成為您想要的結果。以下是java中完成兼容ie6 7 8 9的spring4+websocket正文


1.應用ruby eventmachine和em-http-server gem,完成一個簡略的供給文件下載功效的HttpServer

2.應用了EM的FileStreamer來異步發送文件,發送文件時先組裝了header,然後挪用FileStreamer

require 'rubygems'
require 'eventmachine'
require 'em-http-server'

class HTTPHandler < EM::HttpServer::Server
 attr_accessor :filename, :filesize, :path

 def process_http_request
 #send file async
 if @http_request_method.to_s =~ /GET/ && @http_request_uri.to_s.end_with?(filename)
  send_data "HTTP/1.1 200 OK\n"
  send_data "Server: XiaoMi\n"
  send_data "Connection: Keep-Alive\n"
  send_data "Keep-Alive: timeout=15\n"
  send_data "Content-Type: application/octet-stream\n"
  send_data "Content-Disposition: filename='#{filename}'\n"
  send_data "Content-Length: #{filesize}\n"
  send_data "\n"

  streamer = EventMachine::FileStreamer.new(self, path)
  streamer.callback {
  # file was sent successfully
  close_connection_after_writing
  }
 else
  response = EM::DelegatedHttpResponse.new(self)
  response.status = 200
  response.content_type 'text/html'
  response.content = "Package HttpServer<br>usage: wget http://host:port/#{filename}"
  response.send_response
 end
 end

end

EM::run do
 path = '/tmp/aaa.tar.gz'
 EM::start_server("0.0.0.0", 8080, HTTPHandler) do |conn|
 conn.filename = File.basename(path)
 conn.filesize = File.size(path)
 conn.path = path
 end
end

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved