我已经建立了一个简单的单服务服务器,它可以很好地处理小型测试文件,但是当我尝试运行更大,更实用的文件时,出现了问题。
发送5.2 MB文件可以正常工作。发送30.3 MB文件有效,但需要很长时间(比如15分钟左右)。发送38.5 MB文件时,服务器会收到它,但随后它会抛出错误:msconvert_server.rb:20:in 'write': Invalid argument - 179.raw (Errno::EINVAL)
(179.raw是文件的名称)。
我不知道为什么会这样。 This forum似乎有了答案,虽然它确实加快了发送和接收时间并且也获得了第20行,但在另一点失败了。我不相信TCP有任何文件大小限制,这让我相信问题在于Ruby代码。有没有人看过这个问题,或者对这里可能发生的事情有所了解?
这是代码。
服务器:
require 'socket'
server = TCPServer.open(2000)
loop {
client = server.accept
filename = client.gets.chomp
puts "Reading contents of #{filename}.raw"
raw_data = client.gets("\r\r\n\n").chomp("\r\r\n\n")
(Line 20, where error occurs) File.open(filename + ".raw", 'wb') {|out| out.print raw_data}
puts "Converting #{filename}"
#It's lame to have a script run a script, but it's the only way to get this to work.
system "scriptit.bat " + filename + ".raw"
puts "Sending contents of #{filename}.mzML"
client.print IO.read(filename + ".mzML")
client.print "\r\r\n\n"
puts "Done"
client.close
}
客户端:
host = config_value("//Host/@ip")
port = 2000
client = TCPSocket.open(host, port)
fileName = @file.split("/")[-1].chomp(File.extname(@file))
puts "Sending raw file"
client.puts fileName
client.print(File.open("#{@file}", "rb") {|io| io.read})
client.print("\r\r\n\n") #This is the delimiter for the server
puts "Receiving mzML file"
File.open("#{$path}../data/spectra/#{fileName}.mzML", 'wb') {|io| io.print client.gets("\r\r\n\n")}
client.close
答案 0 :(得分:2)
我找到了问题的解决方案。通过应用a previous question中的相同解决方案,我将代码更改为:
服务器强>: 要求'插座'
server = TCPServer.open(2000)
loop {
client = server.accept
filename = client.gets.chomp
puts "Reading contents of #{filename}.raw"
raw_data = client.gets("\r\r\n\n").chomp("\r\r\n\n")
file = File.open(filename + ".raw", 'wb')
file.print raw_data
file.close
puts "Converting #{filename}"
#It's lame to have a script run a script, but it's the only way to get this to work.
system "scriptit.bat " + filename + ".raw"
puts "Sending contents of #{filename}.mzML"
data = IO.read(filename + ".mzML")
client.print data
client.print "\r\r\n\n"
puts "Done"
client.close
}
<强>客户端强>:
host = config_value("//Host/@ip")
port = 2000
client = TCPSocket.open(host, port)
fileName = @file.split("/")[-1].chomp(File.extname(@file))
puts "Sending raw file"
client.puts fileName
data = IO.read("#{@file}")
client.print data
client.print "\r\r\n\n" #This is the delimiter for the server
puts "Receiving mzML file"
file = File.open("#{$path}../data/spectra/#{fileName}.mzML", 'wb')
data = client.gets("\r\r\n\n")
file.print data
client.close
似乎扩展IO单行解决了我的大部分文件Ruby问题。