Parsing Hashtable Data
I used two platforms demo for interaction:
【Android NDK RealTime:demo_loadBalancing】
【Unity RealTime:demo-particle-unity】
Android:mLoadBalancingClient.opRaiseEvent (false, count, 0)
> Unity:OnEvent ( Photon.EventData Photo event) works normally and gets the detailed information;
However, I don't know how to parse the data sent by unity on Android platform
【Unity】
【Android】
I don't know how to get the value of posx, posy
【Android NDK RealTime:demo_loadBalancing】
【Unity RealTime:demo-particle-unity】
Android:mLoadBalancingClient.opRaiseEvent (false, count, 0)
> Unity:OnEvent ( Photon.EventData Photo event) works normally and gets the detailed information;
However, I don't know how to parse the data sent by unity on Android platform
【Unity】
public Hashtable WriteEvMove() { Hashtable evContent = new Hashtable(); evContent[(byte)1] = new byte[] { (byte)this.PosX, (byte)this.PosY }; return evContent; }
this.LoadBalancingPeer.OpRaiseEvent(DemoConstants.EvPosition, this.particlePlayer.WriteEvMove(), new RaiseEventOptions(), new SendOptions() { Reliability = this.SendReliable });
public virtual bool OpRaiseEvent(byte eventCode, object customEventContent, RaiseEventOptions raiseEventOptions, SendOptions sendOptions) { ... paramDict[(byte)ParameterCode.Code] = (byte)eventCode; if (customEventContent != null) { paramDict[(byte)ParameterCode.Data] = customEventContent; } //UnityEngine.Debug.Log("this.SendOperation(OperationCode.RaiseEvent, paramDict, sendOptions); OperationCode.RaiseEvent = " + OperationCode.RaiseEvent); return this.SendOperation(OperationCode.RaiseEvent, paramDict, sendOptions); }
【Android】
void NetworkLogic::customEventAction(int playerNr, nByte eventCode, const ExitGames::Common::Object& eventContent) { ExitGames::Common::Hashtable evData = ExitGames::Common::ValueObject<ExitGames::Common::Hashtable>(eventContent); //??????????? I don't know how to get the value of posx, posy }
I don't know how to get the value of posx, posy
0
Best Answer
-
Hi @Daguo.
For this kind of question I can recommend to look at demo_typeSupport inside the AndroidNDK Client SDK (or inside the Windows or OSX Client SDK, as all C++ Client SDKs share the same APIs and for quick prototyping with the demos a Desktop platform where you can debug on the local system is usually simpler).
CPhotonLib::sendData() and Listener::customEventAction() from that demo contain example code for how to send and receive all kinds of data.
For your specific question, see the snippet below:// while implementing the receiving code it is often helpful to log the received event to see if its structuring and types match what you expect them to be and if it contains all the expected data EGLOG(ExitGames::Common::DebugLevel::INFO, L"eventContent: %ls", eventContent.toString(true).cstr()); // get the Hashtable that the other client has sent ExitGames::Common::Hashtable evData = ExitGames::Common::ValueObject<ExitGames::Common::Hashtable>(eventContent).getDataCopy(); // get the ValueObject that holds the byte array ExitGames::Common::ValueObject<nByte*> arrObj = ExitGames::Common::ValueObject<nByte*>(evData.getValue(static_cast<nByte>(1))); if(*arrObj.getSizes() == 2) { // get the address of the byte array itself // note: we take the address here, as we read out the individual elements right afterwards and hence won't need the array to stay valid after we have left the scope in which the arrObj is valid. // if you want to access the array outside of the callback, then you need to use getDatyCopy() instead - in that case don't forget to call deallocateArray() on your copy of the array once you don't need it anymore, or it will leak! nByte* pArr = *arrObj.getDataAddress(); // access the individual array elements nByte posX = pArr[0]; nByte posY = pArr[1]; } else ; // something unexpected happened
5
Answers
-
Hi @Daguo.
For this kind of question I can recommend to look at demo_typeSupport inside the AndroidNDK Client SDK (or inside the Windows or OSX Client SDK, as all C++ Client SDKs share the same APIs and for quick prototyping with the demos a Desktop platform where you can debug on the local system is usually simpler).
CPhotonLib::sendData() and Listener::customEventAction() from that demo contain example code for how to send and receive all kinds of data.
For your specific question, see the snippet below:// while implementing the receiving code it is often helpful to log the received event to see if its structuring and types match what you expect them to be and if it contains all the expected data EGLOG(ExitGames::Common::DebugLevel::INFO, L"eventContent: %ls", eventContent.toString(true).cstr()); // get the Hashtable that the other client has sent ExitGames::Common::Hashtable evData = ExitGames::Common::ValueObject<ExitGames::Common::Hashtable>(eventContent).getDataCopy(); // get the ValueObject that holds the byte array ExitGames::Common::ValueObject<nByte*> arrObj = ExitGames::Common::ValueObject<nByte*>(evData.getValue(static_cast<nByte>(1))); if(*arrObj.getSizes() == 2) { // get the address of the byte array itself // note: we take the address here, as we read out the individual elements right afterwards and hence won't need the array to stay valid after we have left the scope in which the arrObj is valid. // if you want to access the array outside of the callback, then you need to use getDatyCopy() instead - in that case don't forget to call deallocateArray() on your copy of the array once you don't need it anymore, or it will leak! nByte* pArr = *arrObj.getDataAddress(); // access the individual array elements nByte posX = pArr[0]; nByte posY = pArr[1]; } else ; // something unexpected happened
5 -
0