Code Monkey home page Code Monkey logo

Comments (9)

zbalkan avatar zbalkan commented on May 26, 2024

This example is oversimplified by the way. I also removed \\.\pipe\ from all names to make .StartsWith() work.

from h.pipes.

HavenDV avatar HavenDV commented on May 26, 2024

In fact, I want to replace

var connectionPipeName = $"{PipeName}_{++NextPipeId}";

to

var connectionPipeName = $"{PipeName}_{Guid.NewGuid()}";

P.S. I released this change.

from h.pipes.

HavenDV avatar HavenDV commented on May 26, 2024

The library also contains PipeWatcher.GetActivePipes(), which contains the following code:

public static IReadOnlyCollection<string> GetActivePipes()
{
    return Directory
        .EnumerateFiles(@"\\.\pipe\")
        .Select(path => path.Replace(@"\\.\pipe\", string.Empty))
        .ToList();
}

But I do not recommend using pipe file enumeration in principle, it is very slow.

from h.pipes.

HavenDV avatar HavenDV commented on May 26, 2024

Regarding the problem with invalid characters, yes, EnumerateFiles returns such an exception when a path contains System.IO.Path.GetInvalidPathChars:

T:System.ArgumentException:
//     path is a zero-length string, contains only white space, or contains invalid
//     characters. You can query for invalid characters by using the System.IO.Path.GetInvalidPathChars
//     method. - or - searchPattern does not contain a valid pattern.

But as I said, EnumerateFiles is generally not good for keeping track of pipes, it is very slow.

from h.pipes.

HavenDV avatar HavenDV commented on May 26, 2024

At the moment I'm trying to figure out why you need to monitor active pipes at all?

from h.pipes.

zbalkan avatar zbalkan commented on May 26, 2024

I don't need all the pipes but I just need to have what server uses currently. I see that during operation I can have:

  • pipename
  • pipename_1
  • pipename_2, etc.

But if the client only knows pipename, then client is unable to connect to the server when numbers are there. So, I had to find a pipe that starts with pipename. To solve this, I enumerated all the pipes and pick a suitable one with the code above. However, in case there are multiple pipes at the same time, it takes only the first one and it might be an incorrect one.

from h.pipes.

HavenDV avatar HavenDV commented on May 26, 2024

Ok, the problem is clear. I will add a Connection.PipeName property that will contain the currently used name.
The principle of the server is that there is a common pipe through which a unique pipeName is transmitted for each client, which is used for a direct connection with the client. Without this trick, only one client would be able to connect to the server. But, in fact, there is already a SingleConnectionPipeServer class that is optimized for a single connection.

from h.pipes.

HavenDV avatar HavenDV commented on May 26, 2024

I have released a new version. I removed the Connection.Id and Connection.Name properties because the Connection.PipeName will be unique.

from h.pipes.

zbalkan avatar zbalkan commented on May 26, 2024

That's a huge change. Thank you for quick reply. I'll try to use this one. And also will try SingleConnectionPipeServer, which seems to be the best way for my use case.

from h.pipes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.