(ÀÌ ÀåÀÇ ´ëºÎºÐÀº Michael NeumannÀÌ ½è´Ù.)
Ruby´Â °´Ã¼ÁöÇâÀûÀÎ ½ºÅ©¸³Æ® ¾ð¾î´Ù. ÀÌ¹Ì ÀϺ»¿¡¼´Â ÇÁ·Î±×·¡¹ÖÀÇ ÁÖ·ù¸¦ ÀÌ·ç°í ÀÖÀ¸¸ç, ±× ¿ÜÀÇ °÷À¸·Îµµ È®´ëµÇ¾î °¡°í ÀÖ´Ù.
Ruby·Î XML-RPC¸¦ »ç¿ëÇϱâ À§Çؼ´Â ¸ÕÀú Yoshida MasatoÀÇ xmlparser ¸ðµâ(James ClarkÀÇ expat ÆÄ¼ÀÇ ·çºñ¿ë ·¡ÆÛ)À» ¸ÕÀú ¼³Ä¡ÇØ¾ß ÇÑ´Ù. ÀÌ ¸ðµâÀº Ruby Application Archive¿¡¼ ãÀ» ¼ö ÀÖ´Ù.
xmlrpc4r ¸ðµâÀ» ´ÙÀ½°ú °°ÀÌ ¼³Ä¡Ç϶ó:
bash$ tar -xvzf xmlrpc4r-1_2.tar.gz bash$ cd xmlrpc4r-1_2 bash$ su root -c "ruby install.rb" |
´ÙÀ½Àº °£´ÜÇÑ Ruby Ŭ¶óÀ̾ðÆ®ÀÌ´Ù:
require "xmlrpc/client" # Make an object to represent the XML-RPC server. server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php") # Call the remote server and get our result result = server.call("sample.sumAndDifference", 5, 3) sum = result["sum"] difference = result["difference"] puts "Sum: #{sum}, Difference: #{difference}" |
´ÙÀ½Àº °£´ÜÇÑ Ruby ¼¹öÀÌ´Ù:
require "xmlrpc/server" s = XMLRPC::CGIServer.new s.add_hanlder("sample.sumAndDifference") do |a,b| { "sum" => a + b, "difference" => a - b } end s.serve |
À§ÀÇ ÄÚµå´Â ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÒ ¼öµµ ÀÖ´Ù:
require "xmlrpc/server" s = XMLRPC::CGIServer.new class MyHandler def sumAndDifference(a, b) { "sum" => a + b, "difference" => a - b } end end s.add_handler("sample", MyHandler.new) s.serve |
CGI ±â¹ÝÀÇ ¼¹ö ´ë½Å µ¶¸³ ¼¹ö·Î ½ÇÇàÇÏ·Á¸é µÎ¹øÂ° ÁÙÀ» ´ÙÀ½°ú °°ÀÌ ¹Ù²Ù¸é µÈ´Ù:
s = XMLRPC::Server.new(8080) |