Skip to main content

Integrate a Local Dedicated Server to the DSM

Last updated on

Make sure you set up all this function when on the dedicated server scene or level. And the function is only called by the server, not the client.

  1. Register your Local Dedicated Server to the DSM.

    FString IpAddress = FString("https://127.0.0.1");
    int32 Port = 7777;
    FString ServerName = FString("my-awesome-game-server");

    FRegistry::ServerDSM.RegisterLocalServerToDSM(IpAddress, Port, ServerName, FVoidHandler::CreateLambda([]()
    {
    // Do something if RegisterLocalServerToDSM has been successful
    }), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
    {
    // Do something if RegisterLocalServerToDSM has an error
    UE_LOG(LogTemp, Log, TEXT("Error RegisterLocalServerToDSM, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
    }));
  2. Once completed, if any match request is received, the Dedicated Server will accept the connections from game clients and will be able to start the match.

  3. After the match is finished, you will need to make sure the Dedicated Server is no longer registered in the Dedicated Server Management. Call this function to deregister the Dedicated Server.

    FString ServerName = FString("my-awesome-game-server");

    FRegistry::ServerDSM.DeregisterLocalServerFromDSM(ServerName, FVoidHandler::CreateLambda([]()
    {
    // Do something if DeregisterLocalServerFromDSM has been successful
    }), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
    {
    // Do something if DeregisterLocalServerFromDSM has an error
    UE_LOG(LogTemp, Log, TEXT("Error DeregisterLocalServerFromDSM, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
    }));