Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to User contributions

rmi xml example (xml network communication)

rmi xml example (xml network communication)

Postby Cheramu » 27 May 2012, 21:57

I'm currenly using for my xml communications with the backend. Feel free to use and modify.

It will translate xml send from the server to a method call within you're game.

How to use
You can do postEvent/sendEvent/sendEventImmediate followed by the method params.
See the example below for the xml format the back-end must send.

You can use the following to send a request to you're server
Code: Select all
user.sendEventImmediate ( this.getUser ( ),"AI_COMMAND", "onRecieveXML", "ping/", "STContent="..sXml , sExml )


or use the local one if you have local stored xml that must call a method
Code: Select all
user.sendEventImmediate ( this.getUser ( ),"AI_COMMAND", "onRecieveLocalXML", sXml)


Settings
Set the sServeradress variable or look in the init for the envoirement variable in AI_COMMAND

Example
You send een ping event to you're backend and get a pong response
--sXml
<s>ping</s>

--sExml
<cs>
<c t="sendEvent">
<p>Controller</p>
<p>onError</p>
<p>check youre internet connection</p>
</c>
</cs>

Code: Select all
user.sendEventImmediate ( this.getUser ( ),"AI_COMMAND", "onRecieveXML", "ping/", "STContent="..sXml , sExml )

Youre backend sends the following back.
<cs>
<c t="postEvent">
<p>2</p>
<p>Controller</p>
<p>onLog</p>
<p>pong/p>
</c>
</cs>

the AI_COMMAND will call you're handler


todo
adding some data options like csv <c/>sendEvent,onLog,<c/>
to add https / http options

tips
You probelly have the logic functions of you're game, so make a handler that does the string conversion and calls that function.
Encode you're xml,
Code: Select all
sXml = string.encodeURL( sXml )
Cheramu
Senior Boarder
Senior Boarder
 
Posts: 61

Return to User contributions