What's the different between SendEvent() and SendOperationResponse()?

Options
Hello

SendEvent() and SendOperationResponse() seem the same to me. And I can't find more info in Photon's doc.
I tried them in my unity3D project.

the client side
=========================================================
void Update ()
{
peer.Service();

if (!connected)
return;

if(Input.GetKeyDown(KeyCode.O))
{
var parameters = new Dictionary { { 0, "send OP please" } };
peer.OpCustom(1, parameters, true);
}

if (Input.GetKeyDown(KeyCode.E))
{
var parameters = new Dictionary { { 0, "send event please" } };
peer.OpCustom(2, parameters, true);
}

if (Input.GetKeyDown(KeyCode.D))
{
var parameters = new Dictionary { { 0, "send data please" } };
peer.OpCustom(3, parameters, true);
}
}

public void OnEvent(EventData eventData)
{
reciveCode = eventData.Code;
reciveString = (string)eventData.Parameters[1];
}

public void OnOperationResponse(OperationResponse operationResponse)
{
reciveCode = operationResponse.OperationCode;
reciveString = (string)operationResponse.Parameters[1];
}

public void DebugReturn(DebugLevel level, string message)
{
Debug.Log(level + ": " + message);
}
=========================================================


the server side
=========================================================
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
string message = "";
if(operationRequest.OperationCode == 1)
{
message = "You said \"" + (string)operationRequest.Parameters[0] + "\"";
var response = new OperationResponse(operationRequest.OperationCode, new Dictionary { { 1, message } });
this.SendOperationResponse(response, sendParameters);
}
else if(operationRequest.OperationCode == 2)
{
message = "You said \"" + (string)operationRequest.Parameters[0] + "\"";
EventData @event = new EventData(5, new Dictionary { { 1, message } });
SendEvent(@event, sendParameters);
}
else if (operationRequest.OperationCode == 3)
{
byte[] b = { 7, 8 };
//message = "You said \"" + (string)operationRequest.Parameters[0] + "\"";
SendData(b, sendParameters);

}
}

=========================================================

My questions are
1.I can use both SendEvent() and SendOperationResponse() to send message to client. What's the different between them?
When should I use SendEvent() and when should I use SendOperationResponse()?
2.If I use SendData(), unity's will get a message "ALL: No regular operation UDP message : 7".
How to use SendData()?

Any help will be great.

Thank you.


Best Answers

Answers

  • Bad_Shiba
    Options
    Got it.

    Thank you :) .