2

我创建了一个小型 HTTP 服务器,TCPServer.new原因是我没有使用任何服务器库,我只需要提供一个 HTML 页面、一个 JS 文件和一些图像。

我想知道当我收到文件请求时如何发送图像/favicon.ico/head.jpg. 我应该使用socket.send吗?或者我应该使用缓冲区发送?

File.open('../Aimages/head.jpg', 'rb') do |file|
    while chunk = file.read(SIZE)
    socket.write(chunk)
  end
end

发送图像时标题重要吗?

4

0 回答 0