Using SendEvent to send a msg from Server to Client, SendEvent's parameter EventCode is byte, max N?

Options
Does this mean I'm only able to send up to 252 unique EventCodes to the client (ClientPeer)?
What If I need more than that? like 1000 kind of events...

Thanks in advance :smile:

Comments

  • shaun_cmune
    edited August 2017
    Options
    EventData.Code is a byte, so yes it's limited to a range of 0-255.

    Why would you want 1000 events anyway, that would be difficult to manage and doesn't make sense. You can fold more data into a single event with some smart use of the Dictionary<byte, object> Parameters member.

    Best regards,
    Shaun
  • qugen
    Options
    > @shaun_cmune said:
    > EventData.Code is a byte, so yes it's limited to a range of 0-255.
    >
    > Why would you want 1000 events anyway, that would be difficult to manage and doesn't make sense. You can fold more data into a single event with some smart use of the Dictionary Parameters member.
    >
    > Best regards,
    > Shaun

    First of all thank you for your help, it's great to see there is a community to help each other.

    I want to send the player's environment information (such as what tiles/sprites are around him) for a MMO through an Event so the player doesn't need to request it through an operation. I know this is only 1 event, but what if the game gets bigger and deeper in content?

    I imagined using the Dictionary Parameters as you say, by using a dictionary entry to hold an Int for further events seggregation but I wanted to ask this question:

    Is an Event the right way to achieve this? Or should I rather use an Operation Request from the Client to the Server?

    Thanks a lot
  • chvetsov
    Options
    hi, @qugen
    i should add that you are limited even more. let say you may use events from 0 to 250. all above reserved by photon.

    SendEvent/SendOperationResponse are the main way to communicate between server and client. SendOperation is main way to communicate between client and server.

    so, in general you send operation(request). if server needs to answer back only to sender(for instance in case of error) it may send Operation Respnose. if server needs to send something to many clients or to other client then use events

    if you need more then 200 operations/events then you need to add int/short/long value to dictionary in order to signal what kind of operation is this

    best,
    ilya
  • shaun_cmune
    Options
    Hi @qugen,

    To add to what @chvetsov said, here's how I would suggest you approach your problem;
    - Operation -> Client asks the Server to do something, and includes some data
    - Operation Response -> Server uses these usually to let a Client know if the operation was successful or not
    - Event -> Server raises these, to be sent to one or more clients (this is usually where a bulk of your bandwidth goes)

    The way we use Ops and Events is pretty simple, although we did implement our own custom binary serialization, to make our lives easier.
    Example Operation
    public void SendPlayerWeaponSlot(WeaponSlotType loadoutSlot)
    {
    	using(var stream = new MemoryStream())
    	{
    		EnumProxy<WeaponSlotType>.Serialize(stream, loadoutSlot);
    		var data = new Dictionary<byte, object>()
    		{
    			{ DATA_ID, stream.ToArray() }
    		};
    				
    		SendOperation(4, data, true);
    	}
    }
    Here, the client tells the server which weapon slot they wish to activate. The server ultimately decides if they can or not. But we just send some simple data, which happens to be an enum, to the server. Note, that we don't care about the Operation Response here.
    Example Event
    public RoomEvent SendScoreboard(PhotonScoreboardData scoreboardData)
    {
    	using (var stream = new MemoryStream())
    	{
    		PhotonScoreboardDataProxy.Serialize(stream, scoreboardData);
    		var data = new Dictionary<byte, object>()
    		{
    			{ 0, stream.ToArray() }
    		};
    				
            return new RoomEvent(m_BaseRoom, new EventData() { Code = 21, Parameters = data } );
    	}
    }
    Here the server sends a detailed type back to the client, to update the scoreboard. As you can see the EventCode is fairly low - and this is the point I was making before - you can easily send a Dictionary of objects back to your client as one event (like NearbyTileSet of Dictionary<int, Tile>) as a single event.

    It's totally fine to make use of Events (one to many), and I would recommend them over using Operation Responses (one to one). The real problem you'll have to solve is more one of optimization - i.e. how do I only send the relevant data to each player, and keep it small. The mode and method of transport will just be an Event packed with fairly sophisticated type.

    Hope this helps :)

    Best regards,
    Shaun

  • qugen
    Options
    Thank you all for your help, it was very useful!