Search Unity

NamedPipeServerStream in Unity

Discussion in 'Scripting' started by Brathnann, Oct 2, 2020.

  1. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Has anybody been successful in using Named Pipes in Unity.
    We have two Unity programs, one is a launcher and the other(s) will be launched from it. Think of something like steam. I already have a launcher launching the other experience and now I need to transfer data.

    I get a not implemented error when I try to do a new NamedPipeServerStream, so I'm guessing Unity doesn't have an implementation for it, but just wondering if anybody found a solution for this.

    Thanks!
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Interesting find.

    I'm basically running into what this guy is facing
    https://forum.unity.com/threads/namedpipes-not-implemented-in-unity-2019-1-4f1.692029/

    Unfortunately, he doesn't appear to have a solution and no responses.

    Basically this call

    await pipeServer.WaitForConnectionAsync(token);

    throws an error with "The method or operation is not implemented.".

    The post you linked does mention the synchronous version working.
     
  4. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    125
    Hi there!

    I've been working with Named Pipes recently and I ran across tons of issues myself and found this post by googling.
    After tons and tons of experimentation I finally got it working.
    I'm posting my solution here just in case people in the future run across this thread just like I did.

    First I was working with 2019.4.12 and in the Editor everything worked fine, I could create Server Pipes and Client Pipes and communicate between them.
    Then the issue came when I made a Windows Build, all of a sudden the log was saying "NamedPipeServerStream is not implemented!"
    However the client has no issues, it seems that NamedPipeClientStream is implemented.
    And again no issues in the Editor, I don't understand how the Editor apparently has NamedPipeServerStream implemented while the build does not.

    I tried everything, updating to 2019.4.20, tried Mono, tried IL2CPP, tried .NET 2 and .NET 4, everything still said "not implemented"
    The solution was swapping out to 32 bit (x86 instead of x86_64)
    And with that now everything works.

    So here's my exact working Server setup:
    - Unity 2019.4.20f1
    - Windows
    - 32bit (x86)
    - Mono
    - .NET 4.x

    And again the client had no issues so I'm running it on my standard parameters and everything works.
    Client Setup:
    - Unity 2019.4.12f1
    - Windows
    - 64bit (x86_64)
    - Mono
    - .NET Standard 2.0

    I create 2 pipes on the Server (one for reading and one for write) and 2 more on the Client.
    Each pipe on a separate thread, 2 threads on the server and 2 threads on the client
    Code (CSharp):
    1.  
    2. new NamedPipeServerStream("LiveChat_SR_CW", PipeDirection.In); // ServerRead_ClientWrite
    3. ...
    4. new NamedPipeServerStream("LiveChat_SW_CR", PipeDirection.Out); // ServerWrite_ClientRead
    5. ...
    6. new NamedPipeClientStream(".", "LiveChat_SW_CR", PipeDirection.In); // ServerWrite_ClientRead
    7. ...
    8. new NamedPipeClientStream(".", "LiveChat_SR_CW", PipeDirection.Out); // ServerRead_ClientWrite
    9.  
    Also I am not using async, not sure if that has anything to do with it.
    Code (CSharp):
    1. pipeReadServer.WaitForConnection();
    2. ...
    3. string message = streamReadString.ReadString();

    I was going insane trying to solve this and finally got it working, hopefully this post can help someone in the future!
    Cheers!

    EDIT: I made this video documenting my process so I remember it in the future and hopefully it might help someone else who stumbles upon this post:
     
    Last edited: Mar 6, 2021
    diegoop, ANdys, marie-hmm and 4 others like this.
  5. marie-hmm

    marie-hmm

    Joined:
    Mar 25, 2016
    Posts:
    11
    Bump

    Unity?