microsoft / MixedRealityToolkit

The MixedRealityToolkit is a collection of scripts and components intended to accelerate the development of mixed reality applications targeting Windows Mixed Reality.
MIT License
858 stars 276 forks source link

HoloToolkit - How can I create PERSISTENT session from console/web based client (and close from another independent client)? #82

Open S-Gurpreet opened 7 years ago

S-Gurpreet commented 7 years ago

Hi, I'm using HoloToolkit library in C# console (and web) applications, only to create a session (to which other HoloLens based clients will connect later). But it is only creating ADHOC session despite passing SessionType as PERSISTENT.

Following is the Main() function code:

XToolsApp xToolsApp = new XToolsApp();
Timer timer = new Timer(60);
timer.Elapsed += (source, e) => { xToolsApp.Update(); };
timer.Start();
NetworkConnectionData networkConnectionData = new NetworkConnectionData(xToolsApp)
{
    UserName = "TestUser",
    ServerAddress = "localhost:20602",
    ViewerAddress = "localhost:20603"
};
xToolsApp.SessionManagerListener.SessionAdded += (session) =>
{
    if (session.GetName().GetString().Equals("Default", StringComparison.OrdinalIgnoreCase))
    {
        xToolsApp.CreateSession("TestSession", SessionType.PERSISTENT);
    }
};
Console.ReadLine();

In above Main() function code, the statement xToolsApp.CreateSession("TestSession", SessionType.PERSISTENT) calls the following function:

public bool CreateSession(string sessionName, SessionType sessionType)
{
    XString nameXString = new XString(sessionName);

    LogWriteLine("Creating Session " + sessionName);
    if (!this.SessionManager.CreateSession(nameXString, sessionType))
    {

        LogWriteLine("Failed to request a new session!");

        return false;

    }

    return true;

}

Then, finally, in above function, the statement this.SessionManager.CreateSession(nameXString, sessionType) calls following method which was auto generated by HoloToolkit.Sharing library and I think this code calls native code (inside SharingClient.Dll file which is placed in bin folder):

public virtual bool CreateSession(XString sessionName, SessionType type)
{
    bool ret = SharingClientPINVOKE.SessionManager_CreateSession__SWIG_1(swigCPtr, XString.getCPtr(sessionName), (int)type);
    return ret;
}

So, you see that I'm passing Session type as PERSISTENT but I still always get only ADHOC session created, which closes itself as soon as my client leaves that session (as no other user is present in that session). What should I do to get PERSISTENT session created from my client code?

Finally, how can I close it whenever required from (any) client, by getting reference to it?

mohamedmansour commented 7 years ago

I am having this issue as well. There are a couple of bugs for ADHOC sessions too, that ports leak #84 . Seems the binding for PERSISTENCE is not correctly modified.

A PR is available that fixes this assumingly https://github.com/Microsoft/HoloToolkit/pull/83