Hello,
I create an object of TCPSocket. Now I can use method “write” to send a string.
What method that I can send a file using TCPSocket?
Sheen Zan
Hello,
I create an object of TCPSocket. Now I can use method “write” to
send a string.
What method that I can send a file using TCPSocket?
Sheen
Zan
Well, in Ruby terms, a file is just a string – once it’s read in.
Lyle Johnson pointed out that you can do this:
ICON_FILE = ‘icon.jpg’
bytes = File.open(ICON_FILE, ‘rb’).read
File.open(‘icon.rb’, ‘w’) do |f|
f.puts “ICON_STRING = #{bytes.inspect}”
end
There’s no reason that you can’t end up treating the TCPSocket the
same way.
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.11.07 at 11.02.28
···
On Thu, 7 Nov 2002 23:48:51 +0900, 张欣 wrote:
Hello,
I create an object of TCPSocket. Now I can use method “write” to
send a string.
What method that I can send a file using TCPSocket?
Well, in Ruby terms, a file is just a string – once it’s read in.
(deleted)
There’s no reason that you can’t end up treating the TCPSocket the
same way.
Well, and in TCP terms, a stream is a stream, whether it was created from
a (Ruby) string or from a file. If the intention is to transfer a file
using TCP then it is much better and easier to use a Ruby library of FTP
instead of reinventing the wheel (well, at least FTP opens two TCP
connections, one for data channel and one for control channel).
Regards,
Bill