CallRemote: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Server client function}} This function allows you to call functions that have been exported with HTTP access by other MTA servers. The calls are asynchronous so you do not get...)
 
Line 24: Line 24:
*'''resourceName:''' This is a name of the resource that contains the exported function you want to call.
*'''resourceName:''' This is a name of the resource that contains the exported function you want to call.
*'''functionName:''' This is a string with the name of the function which you want to call.
*'''functionName:''' This is a string with the name of the function which you want to call.
*'''URL:''' A full URL in the format '''http://hostname/path/file.ext'''. A port can be specified with a colon followed by a port number appended to the hostname.
*'''URL:''' A full URL in the format '''<nowiki>http://hostname/path/file.ext</nowiki>'''. A port can be specified with a colon followed by a port number appended to the hostname.
*'''callback:''' This is the function that should receive the data returned from the remote function call. The argument list should match the format of the data returned.
*'''callback:''' This is the function that should receive the data returned from the remote function call. The argument list should match the format of the data returned.



Revision as of 02:19, 18 November 2007

This function allows you to call functions that have been exported with HTTP access by other MTA servers. The calls are asynchronous so you do not get an immediate result from the call. You can also use this function to access any standard web page by specifying the URL.

Data is passed to the web page via HTTP POST as raw JSON data. The page should return JSON formated data in the page's body.

Note: You can read raw HTTP POST data from PHP using:

[php]
file_get_contents('php://input')

There are various libraries available for parsing JSON data into PHP variables and vice-versa.

Syntax

bool callRemote ( string host, string resourceName, string functionName, function callback, [ arguments... ] )

OR

bool callRemote ( string URL, function callback, [ arguments... ] )

Required Arguments

  • host: This is a host name (and optionally port) of the server you wish to connect to.
  • resourceName: This is a name of the resource that contains the exported function you want to call.
  • functionName: This is a string with the name of the function which you want to call.
  • URL: A full URL in the format http://hostname/path/file.ext. A port can be specified with a colon followed by a port number appended to the hostname.
  • callback: This is the function that should receive the data returned from the remote function call. The argument list should match the format of the data returned.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • arguments: Any arguments you may want to pass to the function when it is called. Any number of arguments of can be specified, each being passed to the designated function.

Returns

Returns true if the function has been called, false otherwise.

Example

Click to collapse [-]
Server

Example needed!


See Also