WebRPC Response

Options
Im trying to connect to my server with webrpc and get a response back but i cant catch any response.

Here is my php code, the json sent back should be okay.
<?php
header('Content-Type: application/json');
$request = file_get_contents('php://input');
$decoded = json_decode($request);
$array = null;

if($decoded === null) {
    $req_dump = print_r( "Failed to decode the JSON Object\n", true );
    $fp = file_put_contents('/var/log/gameserv/log2.log', $req_dump,FILE_APPEND );
}

$array = array(
    "ResultCode" => 0,
    "Message" => "Found post!"
);

$out = json_encode($array);
echo $out;
?>
Then in unity:
public void OnWebRpcResponse (OperationResponse operationResponse) {
	Debug.Log ("RECEIVING SOMETHING!");
	if (operationResponse.ReturnCode != 0) {
		Debug.Log ("WebRPC operation failed: " + operationResponse.ToStringFull ());
		return;
	}
	WebRpcResponse webRpcResponse = new WebRpcResponse (operationResponse);
	if (webRpcResponse.ReturnCode != 0) {
		Debug.Log ("WebRPC " + webRpcResponse.DebugMessage);
		return;
	}
	Dictionary<string, object> parameters = webRpcResponse.Parameters;
	foreach (KeyValuePair <string,object> pair in parameters) {
		Debug.Log(string.Format("KEY {0} / VALUE: {1}", pair.Key, pair.Value));
	}
}
Not sure why im not getting any result back. Server side i can see the webrpc and parameters sent and can decode the object no problem. But cant get anything from it. I tryed with Postman and it was working well, im getting the resultcode 0 and found post! message.

Any idea?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Aenil,

    Thank you for choosing Photon!

    From your web server, you can log the WebRPC calls initiated by the Photon client?

    Are you using PUN Classic or PUN2?
    How do you implement OnWebRpcResponse callback?
    Do you use Photon Cloud or self-hosted Photon Server?
    Double check the WebRPC configuration.
  • Aenil
    Options
    On the web server i can see exactly what i'm sending from photon and use it or send back. And like i said i used Postman to send a post with a json object to my server and got the string back in postman. So the server is actually receiving and sending back correctly.
    Im using PUN2 and photon cloud.
    I have no real method of using onwebrpc response, i searched the web on how to implement it and all i saw was alot of function using either OnOperationResponse or OnWebRpcResponse. So all i did is copy that function into my code and make sure it was looking "okay"

    Is there a way to call that function or activate it somehow?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Aenil,

    You should register the callback class or extend MonoBehaviourPunCallbacks and override the callbacks you want.
    More details here.
  • Aenil
    Options
    JohnTube, i love you :)
    
    RECEIVING SOMETHING!
    UnityEngine.Debug:Log(Object)
    CharacterCreate:OnWebRpcResponse(OperationResponse) (at Assets/CharacterCreate.cs:51)
    Im really noob with unity i just started all this this summer so having extended class and such is pretty much my limit right now lol, but yeah i got it working by changing monobehavior with this:

    public class CharacterCreate : MonoBehaviourPunCallbacks, IWebRpcCallback {