From: Sheen Zan Date: 2002-11-08T01:46:40+09:00 Subject: Re: A Question About TCPSocket Now I know what wrong I am. The problem was not TCPSocket,but it was the File.open. I used file = File.open("filename"). When I changed file = File.open("filename","rb"), it is all OK. Thanks Sheen Zan ======= 2002-11-08 01:04:00 ======= >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? >> 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 = = = = = = = = = = = = = = = = = = = =         Sheen Zan         zx@is.pku.edu.cn           2002-11-08