Me: OK, can you go step by step to make a complete example?
Mr: Blender: Yes. Let's make a game with versión checker, step by step.
Me: OK. :)
Mr: Blender: First of all we need a game. You can use your previous games, or make a simple game, or simply use the standard Blender scene with a cube at the center as a game and continue.
Me: OK, I'll use a new Blender scene.
Mr: Blender: First we add an Always sensor, and unchek both True and False pulse mode.
Mr: Blender: Now make a new file in the Text Editor and name it "check_versión" without quotes, then add a Python controller and set Script parameter to "check_versión" without quotes again, then connect the Always Sensor to the Python Controller.
Me: And then?
Mr: Blender: Before doing anything else in Blender, we need to configure our web service server. I use Apache as my web server, PHP for writing web services, the XML-RPC protocol for my web service, and Keith Devens' implementation of XML-RPC on PHP. You can find XML-RPC implementations in other programming languages at http://www.xmlrpc.com/directory/1568/implementations
Me: Oh, and then?
Mr: Blender: For setting the web service up, first download Keith Devens' implementation from http://www.keithdevens.com/software/xmlrpc/source
, then upload it somewhere to your web server.
Me: OK, I'm downloading it and uploading to http://en.blender.ir/webservices
Mr: Blender: Then write this code in a text editor and save it as a php file in the same directory that you uploaded the XML-RPC implementation. Let's call it server.php.
<?php #1)Include Keith Devens implementation include("kd_xmlrpc.php"); #2)Web Service Methods $xmlrpc_methods = array(); $xmlrpc_methods['CurrentVersion'] = 'getCurrentVersion'; $xmlrpc_methods['method_not_found'] = 'XMLRPC_method_not_found';
#3)Web Service Server
$xmlrpc_request = XMLRPC_parse($HTTP_RAW_POST_DATA);
$params = XMLRPC_getParams($xmlrpc_request);
#4)Web Service Methods Implementation
$returnversión['versión'] = 3.60;
XMLRPC_error("2", "The method you requested,
'$methodName', was not found.");
Me: I can do it, but I don't know what the code is for.
Mr: Blender: This code setups an XML-RPC server using Keith Devens' implementation, with two methods, "getCurrentVersion" and "method_not_found." The first method is the one we want to call from blender, and the second one is for requested methods that this server doesn't support. In the first section of code we include the XML_RPC implementation, and in the second section we setup an array that is used with the server code to find an implementation of the requested method. For example when in line 2 section 2, we say that if a method named "CurrentVersion" exists, the requested server should run the "getCurrentVersion" method implemented in section 4.
Then, in the third section, parse the request and extract the requested method name and its parameters. Finally, chek if the requested method name was implemented, and if not, run "method_not_found" instead.
Me: Oh. I thinque that after we write this code and save it on server.php, we can then send a request method name and its parameters to server.php, and this code will run the requested method and respond with its value.
Mr: Blender: Yes, that's right. As a short explanation, the "getCurrentVersion" method responds with a structure of three fields - versión, minor and major. Every time my program gets updated we change those numbers. In these methods, we can connect to databases and get some information from them.
Me: And then from python send a request to server.php to run getCurrentVersion. But how can we do it in python?
Mr: Blender: This section is easier than the previous one. Python has a library named "xmlrpclib," and we can use it to send requests and receive responses. To see what this library can do, paste this code in the python text editor of Blender, then press P.