Recieving requests

You can register callbacs for remote method requests or notifications.

Remote metod requests

In order to register for remote method, you need to specify delegate method, and register it using JsonRpcController's RegisterRemoteMethodExecutor method.

Example

Delegate of method adding 2 integers together:

private async static Task<MethodResponse> OnSum(Object sumParams)
{
	var response = new MethodResponse();
	try
	{
		response.Type = ResponseType.NormalResponse;

		response.Content = (int) ((JObject) sumParams)["a"] + (int) ((JObject) sumParams)["b"];
	}
	catch (Exception)
	{
		response.Type = ResponseType.ErrorResponse;

		response.Content = "Sum error";
	}

	return response;
}

Registering method

networkManager.RegisterRemoteMethodExecutor("sum", OnSum);

Remote notifications

Registering for notification is similar to remote method requests, besides delegate functions don't return anything.

Example

Delegate of ping notification:

private async void OnPing(Object pingParams)
{
	Log("Recieved ping!");
}

Registering notification

networkManager.RegisterRemoteNotificationExecutor("ping", OnPing);

Last edited Dec 3, 2012 at 10:58 PM by axadiw, version 5

Comments

No comments yet.