Operation Response

Hello,

I am trying to send a variable from the server to a UE4 client using a photonlistener class. I am trying to avoid using the LoadBalancing server.

My basic code looks like...

Server: (c#)
public void OnLogin(){

perationResponse response = new OperationResponse(ClientOperationResponseCodes.LoggedIn);
response.Parameters = new Dictionary(ClientParameterCodes.Username,"bob");
SendOperationResponse(response, sendParameters);

}

Client: (c++)
void TestClient::onOperationResponse(const OperationResponse& operationResponse)
{
Hashtable opData = ValueObject(operationResponce.GetParameters());
if(opData.getValue(ClientParameterCodes::Username))
{
JString Username = (ValueObject(opData.getValue(ClientParameterCodes::Username)).getDataCopy();
FString UN(Username.UTF8Representation().cstr);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, UN + " Logged into the server");
}
}

Result:
" Logged into the server"

Unfortunately this is not the exact code i have been testing as i am working currently and ive done this from memory. However this is basically what i am trying to do.

Please can someone provide me with some working theory on how to get this working as every time i try to print the username out it is blank.

Kind Regards,

Imperator132k



Comments

  • Hi @Imperator132k.

    Well, after removing all those mistakes that are likely related to "Unfortunately this is not the exact code i have been testing [...] and ive done this from memory." and that prevented the code from compiling, the client code looks fine to me. However there have been quite a few of such bugs, so I am not sure, if all of them have just being caused by reproducing it out of your head or if the original code already had bugs. You should really share the original code. I also don't see any obvious mistakes in the server code.

    Please add this line to the client code and print the returned string somewhere where you can inspect it to see what is actually contained in the received response:
    JString str = operationResponse.toString(true, true, true);
    This way you know if the bug is in the client or in the server code. If "bob" is contained in the returned string, then the problem is in your receiving client side code, otherwise it is in the sending server side code.
  • Thank you very much for your quick response, i'm really looking forward to working with you guys.

    Ironically, after me struggling for a night and half, when i rewrote the test code and work and then brought it home again, it seems to work fine.

    I've included the working code for anyone else struggling in the future:

    Server (c#)
    public void Login(PeerBase peer, OperationRequest operationRequest, SendParameters sendParameters)
    {
    Dictionary parameters = new Dictionary();
    parameters.Add((byte)ClientParameterCode.UserName, "bob");
    OperationResponse response = new OperationResponse((byte)ClientOperationResponceCode.LoggedIn, parameters);
    peer.SendOperationResponse(response, sendParameters);
    }

    Client (c++/UE4)
    void UTestClass::LoginRecieved(const OperationResponse& operationResponse)
    Hashtable opData = operationResponse.getParameters();
    if (opData.getSize() > 0) {
    if (opData.contains((byte)ClientParameterCode::UserName))
    {
    JString Username = ValueObject(opData.getValue((byte)ClientParameterCode::UserName)).getDataCopy();
    FString UN(Username.UTF8Representation().cstr());
    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, UN + " Logged into the server");
    }
    }
    }

    Thank you for all your help once again.

    Imperator