Receive only 1 Event per second - when 5 per second where send

Options
AuronDerStreuner
edited December 2016 in Photon Server
Hello everybody,

I just started working with Photon Server + Unity SDK , and tried to build a very simple app with one cubes moving in random Directions. This Position change should be shared over Photon Server. Problem is the other client is moving in slowmotion since he only receives 1 package per second.
Any help highly appriciated.

Thanks in Advance !


Problem Description:

Clients send 5 Position Updates via Photon Server, but receive only 1 per second


Setup:

* Photon Server - Load Balancing Example App - default Config, Log Level: Debug
* 2 Unity clients
* Photon Server, GameServer and Both client running on same machine
* TimeStamp Format: Minute:Second:Millisecond
* Send TimeStamp is stored into serialized Data


Detailed Description:


* Both Clients connect to the GameServer and send a position Update 5 times per second.
* Both Clients check for incoming events 5x times a second
* After Both Clients Joined the room ( TimeStamp ~6:48:700),
* It took ~10s until the Client1 reveives an position Update from Client 2
* It tool ~2s until client2 receives a position update from Client1


Client1: Receives 1 Position update event per 2 seconds ( no events skiped )
Client2: Receives 1 Position update event per 1 second ( no events skiped)

If Client1 is terminated, Client 2 will still receive 1 event per second until
all events are received


Client1, ID: 361 Log: ( Started First )


RaiseEvent: Agent Model Id: 361 Position: (0.1292572,2.802357,0.0517029) Send TimeStamp: 6:44:637
RaiseEvent: Agent Model Id: 361 Position: (0.5534592,2.802357,0.2213837) Send TimeStamp: 6:44:845
RaiseEvent: Agent Model Id: 361 Position: (1.271221,2.802357,0.5084884) Send TimeStamp: 6:45:35
RaiseEvent: Agent Model Id: 361 Position: (2.282542,2.802357,0.9130169) Send TimeStamp: 6:45:233
RaiseEvent: Agent Model Id: 361 Position: (3.709411,2.802357,1.483765) Send TimeStamp: 6:45:449
RaiseEvent: Agent Model Id: 361 Position: (5.332334,2.802357,2.132933) Send TimeStamp: 6:45:648
RaiseEvent: Agent Model Id: 361 Position: (65.29237,2.802357,26.11695) Send TimeStamp: 6:48:646
RaiseEvent: Agent Model Id: 361 Position: (69.15047,2.802357,27.66019) Send TimeStamp: 6:48:854
... Raise Event Continues in same time distance ...

Receive Event List:
OnEvent: Code: 255 ( Someone joined the game) ( ~ 6:48:646)
Receive Event: at Time 6:58:246, with Data: Agent Model Id: 236 Position: (0.09418116,2.802357,0.1044182) Send TimeStamp: 6:48:289
Receive Event: at Time 7:00:053, with Data: Agent Model Id: 236 Position: (0.4146467,2.802357,0.459717) Send TimeStamp: 6:48:494
Receive Event: at Time 7:02:250, with Data: Agent Model Id: 236 Position: (0.9405221,2.802357,1.042753) Send TimeStamp: 6:48:698

Client2 ID: 236 ( Started Second)

Raise Event Log:
RaiseEvent: Agent Model Id: 236 Position: (0.09418116,2.802357,0.1044182) Send TimeStamp: 6:48:289
RaiseEvent: Agent Model Id: 236 Position: (0.4146467,2.802357,0.459717) Send TimeStamp: 6:48:494
RaiseEvent: Agent Model Id: 236 Position: (0.9405221,2.802357,1.042753) Send TimeStamp: 6:48:698
RaiseEvent: Agent Model Id: 236 Position: (1.678163,2.802357,1.860573) Send TimeStamp: 6:48:901
... Raise Event Continues in same time distance ...

Receive Event Log:
OnEvent: Code: 255 ( Someone joined the game) ( ~ 6:48:698 )
Receive Event: at TimeStamp 6:50:290, with Data: Agent Model Id: 361 Position: (2.282542,2.802357,0.9130169) Send TimeStamp: 6:45:233
Receive Event: at TimeStamp 6:51:85, with Data: Agent Model Id: 361 Position: (3.709411,2.802357,1.483765) Send TimeStamp: 6:45:449
Receive Event: at TimeStamp 6:52:486, with Data: Agent Model Id: 361 Position: (5.332334,2.802357,2.132933) Send TimeStamp: 6:45:648


Core Functions:
// Use this for initialization
void Start () {
	Application.runInBackground = true;
	client = new MyLoadBalancer(ConnectionProtocol.Tcp);
	client.OnOpResponseAction += Client_OnOpResponseAction;
	client.OnStateChangeAction += Client_OnStateChangeAction;
	client.MasterServerAddress = "127.0.0.1:4530"; // TCP
	client.AppVersion = "1.0";
	client.AutoJoinLobby = false;
	client.AppId = "Master";
	client.Connect();
}

private void Client_OnStateChangeAction(ClientState obj)
	{
		Debug.Log("Client STate changed: " + obj.ToString());
		switch (obj) {
			case ClientState.ConnectedToMaster:
				//ExitGames.Client.Photon.Hashtable roomPropsForCreation = new ExitGames.Client.Photon.Hashtable() { { DemoConstants.MapProp, maptype.ToString() }, { DemoConstants.GridSizeProp, gridSize } };
				ExitGames.Client.Photon.Hashtable roomPropsForCreation = new ExitGames.Client.Photon.Hashtable();
				string[] RoomPropsInLobby = new string [] { "Test1"};
				client.OpJoinOrCreateRoom("Demo", new RoomOptions() { CustomRoomProperties = roomPropsForCreation, CustomRoomPropertiesForLobby = RoomPropsInLobby }, null);
				break;
			case ClientState.Joined:
				this.SimIsStarted = true;
				break;
		}
	}

	private void Client_OnOpResponseAction(OperationResponse obj)
	{
		Debug.Log("OnResponseActions: " + obj.DebugMessage);
	}


Class MyLoadBalancer:
// Called 5x per second
private void SendNetworkData(float obj)
	{
		this.loadBalancingPeer.SendOutgoingCommands();
	}

	public override void OnStatusChanged(StatusCode statusCode)
	{
		Debug.Log("MyLoadBalancer: Status changed" + statusCode);
		base.OnStatusChanged(statusCode);
	}
  
// called 5x per second
	private void ReceiveNetworkData(float timestamp) {

		while (true) {
			if (this.loadBalancingPeer.DispatchIncomingCommands()) {

			}
			else {
				//Debug.Log("Dispatch But nothing there");
				break;
			}

			// You could count dispatch calls to limit them to X, if they take too much time of a single frame
		}
	}

	public void SendUpdatePosition(AgentModel model) {
		ExitGames.Client.Photon.Hashtable evContent = new ExitGames.Client.Photon.Hashtable();
		evContent[(byte)1] = model.Serialize();
		Debug.Log("RaiseEvent: " + model.ToString());
		this.loadBalancingPeer.OpRaiseEvent(1, evContent,false, new RaiseEventOptions());
	}


	public override void OnEvent(EventData photonEvent)
	{
		Debug.Log("OnEvent: Code: " + photonEvent.Code.ToString());
		base.OnEvent(photonEvent);  // important to call, to keep state up to date
		switch (photonEvent.Code) {
			case 1:
				ReadEvMove((ExitGames.Client.Photon.Hashtable)photonEvent[ParameterCode.CustomEventContent]);
				break;
			default:
				Debug.Log("Not handled event with code: " + photonEvent.Code.ToString());
				break;
		}
	}

	public void ReadEvMove(ExitGames.Client.Photon.Hashtable evContent)
	{
		if (evContent.ContainsKey((byte)1)) {
			byte[] posArray = (byte[])evContent[(byte)1];
			var model = AgentModel.Deserialize(posArray);
			Debug.Log(string.Format("Receive Event: at Time {0}:{1}:{2}, with Data: {3}",
				System.DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond, model.ToString()));
			OnAgentUpdate(model);
		}
		else {
			Debug.Log("No Content send ");
		}
	}