XhrHttpHTML 5 for monkey
Monkey Forums/User Modules/XhrHttpHTML 5 for monkey
| ||
XhrHttpHTML 5 is a little networking module for HTML 5 which enable you to do GET and POST requests easily. Its built on the XmlHttpRequest level 2 architecture. I made this for the game i am creating which will communate with a server api in C# (using the PubNub architecture) so i release it as open source under the mit license. http://code.google.com/p/monkey-xhrhttphtml5/ Here the feature : - GET and POST support. - Handle request status easily. - The requests are async which mean it won't block your game. - There a kind of timeout support integrated however you could easily reproduce that. If the request isnt success in like 5 seconds you could easily resend a new one or show an error. - Can make more than one request with the same object. Demo is included. There exactly 2 classes.. the XhrObject which is the actual object needed for the requests and the XhrStatus class. Class XhrStatus Const IDLE:Int = 0 Const CONNECTED:Int = 1 Const REQUEST_SENT:Int = 2 Const STARTED_RECEIVING_DATA:Int = 3 Const DONE_RECEIVING_DATA:Int = 4 Const SUCCESS:Int = 5 Const ERROR:Int = 6 Const TIMEOUT:Int = 7 End The XhrStatus class is essentially only constants which define the status number of the request. So doing xhrobject.GetStatus() will get you the status of the request, if its a success you can compare against the SUCCESS constant. or just use the IsSuccess method implemented which check that for you. Here the full list of methods the object provide.. Class XhrObject = "XhrObject" Method Get:Void(url:String, timeout:Int = 3000) Method Post:Void(url:String, args:String, timeout:Int = 3000) Method GetServerStatusCode:Int() Method GetStatus:Int() Method GetRequestState:Int() Method GetResult:String() Method GetMessage:String() Method IsSuccess:Bool() Method IsFailure:Bool() Method Reset:Void() End Class Note: This won't support all the platforms because TCPStream are already available out of the box in monkey. Enjoy! |
| ||
Version 1.1 is now live. - Added events such OnRequestSuccess, etc.. which you can override in your own object. Read the demo file for more details. |
| ||
couldn't download from freakin google. Why did you not upload it to hell directly. </sarcasm> (the page also freezes my connection.. on android of course) |
| ||
Here's a rehost of the archive for it https://dl.dropboxusercontent.com/u/116871/xhrhtml5-1.0.7z |
| ||
For the record, 'brl.httprequest' is a portable replacement that handles this. |
| ||
make it compatible with windows targets and use https???? |