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.
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.
0
Best Answers
-
For the most part, the SendEvent and SendOperationResponse methods are pretty similar, in that they are both designed to do roughly the same thing: send a message to the client. The difference is a little bit more to do with the design of Photon, and how it sets up a nice environment for you to work in.
Note a few basics:
- from the client, you are not able to send an event to the server. You will notice that the PhotonPeer class (of which you use to create a peer on the client-side) only has the method OpCustom, for sending messages to the server, of which sends an operation. We know this, because we can see the message being received on the server-side within the OnOperationRequest method of the PeerBase class, which you use to create a peer on the server-side.
- from the server, you are able to SendEvent and SendOperationResponse within your PeerBase class, of which you use to create a peer on the server-side.
So, from this, we can assume that the idea behind events and operations is that:
- operations tend to be initiated on the client-side, and can optionally be responded to by the server (allowing you to do a question-answer type communication)
- events tend to be initiated on the server-side, sometimes as the result of an operation initiated by the client (for example, when you send a Join operation to the server, it sends an operation response to you, and send an event to other peers)
There is a little bit more to it than that, but that should get you started.5 -
To answer your second question, SendData is mostly used internally by Photon. Personally I would suggest to avoid it as it is very unlikely you'll find a use for it within your code.5
Answers
-
For the most part, the SendEvent and SendOperationResponse methods are pretty similar, in that they are both designed to do roughly the same thing: send a message to the client. The difference is a little bit more to do with the design of Photon, and how it sets up a nice environment for you to work in.
Note a few basics:
- from the client, you are not able to send an event to the server. You will notice that the PhotonPeer class (of which you use to create a peer on the client-side) only has the method OpCustom, for sending messages to the server, of which sends an operation. We know this, because we can see the message being received on the server-side within the OnOperationRequest method of the PeerBase class, which you use to create a peer on the server-side.
- from the server, you are able to SendEvent and SendOperationResponse within your PeerBase class, of which you use to create a peer on the server-side.
So, from this, we can assume that the idea behind events and operations is that:
- operations tend to be initiated on the client-side, and can optionally be responded to by the server (allowing you to do a question-answer type communication)
- events tend to be initiated on the server-side, sometimes as the result of an operation initiated by the client (for example, when you send a Join operation to the server, it sends an operation response to you, and send an event to other peers)
There is a little bit more to it than that, but that should get you started.5 -
To answer your second question, SendData is mostly used internally by Photon. Personally I would suggest to avoid it as it is very unlikely you'll find a use for it within your code.5
-
Got it.
Thank you .0