Squeak ã§èª¬æãã¦ã WikiPhone ã®é¢ç½ãããã¾ãã¡ããåãããªãã¨æãã®ã§ãRuby 1.8.5 ã§ç°¡å㪠WikiPhone ã¯ã©ã¤ã¢ã³ããå®è£ ãã¦ã¿ã¾ããä»ååºåããå´ã¨å ¥åããå´ãå¥ã ã«ä½ã£ã¦ã¿ã¾ããããã©ã¡ãã 40è¡ã¡ãã£ã¨ã§æ¸ãã¾ãã
ãã¤ãã¨ãã¦ã® WikiPhone
WikiPhone ã¯ãããã§ã¯åãªããã¤ãã®ããã«æ¯èãã¾ããURL ã¯ãWikiPhone ãµã¼ãå ã§ããã°ãªãã§ã使ãã¾ããã¡ãã»ã¼ã¸ã®éåä¿¡ã¯ãã®ããã«ãã¾ãã
éä¿¡å´
$ echo "Hi there" | ./wpput.rb http://languagegame.org:9090/chat
åä¿¡å´
$ ./wpget.rb http://languagegame.org:9090/chat Hi there
Ruby + WikiPhone ã§ãã¡ã¤ã«è»¢é
WikiPhone ããã¡ã¤ã«è»¢éã«ä½¿ã£ã¦ã¿ã¾ããåä¿¡å´ããèµ·åãã¾ãã
$ ./wpget.rb http://languagegame.org:9090/chat > dst.html
次ã«éä¿¡å´ãèµ·åãã¾ãã
$ ./wpput.rb http://languagegame.org:9090/chat < src.html
ããµãã§ããããã¡ã¤ã«ãåãåã£ãã¨æã£ããåä¿¡å´ã¯èªå㧠Ctrl + C ãã¾ãã
Ruby 㧠IP é»è©±???
ãã¦ããããã Ruby ã ã㧠VoIP ã®å®é¨ã§ãã/dev/dsp ããã®ã¾ã¾ä½¿ãã¾ããéä¿¡å´ããã
$ ./wpput.rb http://languagegame.org:9090/voip < /dev/dsp
åä¿¡å´ã§ãã
$ ./wpget.rb http://languagegame.org:9090/voip > /dev/dsp
Ruby 㨠Squeak WikiPhone ã®ä¼è©±ãã°ãã¨ãã
/dev/dsp ã¨ããã®ã¯ãé³å£°ã®å ¥åºåãæ±ãããã¤ã¹ã§ãlinux ã cygwin çã§ä½¿ãã¾ãããã㯠Squeak ç´æ£ã® WikiPhone ã¨ã¯äºææ§ãç¡ãã®ã§ãSqueak ã® WikiPhone ã®ä¿¡å·ãæ±ããããã°å¤æããå¿ è¦ãããã¾ããgsm 22050 Hz ã使ã£ã¦ãã¾ãã®ã§ãä¾ãã°ä¼è©±ã®ãã°ãã¨ãã¯ã³ã©ã¤ãã¼ã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
./wpget.rb http://languagegame.org:9090/phone | sox -t gsm -r22050 - -r22050 -c1 -sw -fs log.wav
以ä¸ã« wpget.rb 㨠wpput.rb ã®ã½ã¼ã¹ãè¼ãã¾ãããµã¼ãã«èå³ã®ããæ¹ã¯ http://www.squeaksource.com/WikiPhone.html 㨠Squeak3.8 ã使ã£ã¦ãã ããããªããlanguagegame.org ã¯çç®±ã¨ããå°ããªãµã¼ãã§åããã¦ãã¾ãã®ã§ãé ãã¦ããæ¢ã¾ãã¾ãã
#!/bin/env ruby # wpget.rb: WikiPhone GET client require "socket" require "uri" require 'net/http' def read_a_chunk sock dest = "" line = sock.readline hexlen = line.slice(/[0-9a-fA-F]+/) or raise Net::HTTPBadResponse, "wrong chunk size line: #{line.dump}" len = hexlen.hex break if len == 0 # $stderr.print "length: #{len}\n" sock.read len, dest sock.read 2 # chop CRLF dest end def main if ARGV.size < 1 then $stderr.print "usage: wpget url\n" exit 1 end uri = URI.parse ARGV.first socket = TCPSocket.new(uri.host, uri.port) socket.write "GET #{uri.path} HTTP/1.1\r\n\r\n" begin response = Net::HTTPResponse.read_new(Net::BufferedIO.new(socket)) end while response.kind_of?(Net::HTTPContinue) # response.each { |name, value| $stderr.print "#{name} : #{value}\n" } while true print read_a_chunk(socket) end end $stdout.sync = true main
#!/bin/env ruby # wpput.rb: WikiPhone PUT client require "socket" require "uri" require 'net/http' def post_a_chunk (socket, data) len = data.length header = "#{len.to_s(16)};\r\n"; socket.write(header) socket.write(data) socket.write("\r\n") end def main if ARGV.size < 1 then $stderr.print "usage: wpput.rb url < input\n" exit 1 end uri = URI.parse ARGV.first socket = TCPSocket.new(uri.host, uri.port) socket.write "PUT #{uri.path} HTTP/1.1\r\n" socket.write "Transfer-Encoding: chunked\r\n\r\n" begin while true buffer = $stdin.readpartial 130 post_a_chunk(socket, buffer) end rescue EOFError end end main