It is necessary that within the windows-session of one user one application can send text data to another application.

Tried to use named pipes. The server listens asynchronously, the clients send messages. Everything is good until the moment when another windows user tries to start the server on the same machine.

Maybe you need to call pipes in such a way that the name would be unique for each user? What unique identifiers can I use for this?

Or maybe it is necessary to use something else for communication?

To make it clear that I use_ I quote the client code that sends messages:

public void Send(string SendStr, string PipeName, int TimeOut = 1000) { using (NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", PipeName, PipeDirection.Out, PipeOptions.Asynchronous)) { // The connect function will indefinitely wait for the pipe to become available // If that is not acceptable specify a maximum waiting time (in ms) pipeStream.Connect(TimeOut); if (pipeStream.IsConnected) { using (StreamWriter sw = new StreamWriter(pipeStream)) { sw.WriteLine(SendStr); } } else throw new ApplicationException("Can not establish the messaging."); } } 

Well, the server listens to messages like this:

  public void Listen(string PipeName) { // Set to class level var so we can re-use in the async callback method _pipeName = PipeName; // Create the new async pipe NamedPipeServerStream pipeServer = new NamedPipeServerStream(PipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); // Wait for a connection pipeServer.BeginWaitForConnection(new AsyncCallback(WaitForConnectionCallBack), pipeServer); } 
  • The following idea appeared: The server at startup generates a random name for the pipe and stores it in the user storage, for example, in the registry in the CurrentUser branch. The client part reads the name and uses it to send messages. - Sergej Loos
  • The server at startup generates a random name for the pipe. It is more reasonable to use a certain static prefix plus its own PID. - Akina
  • I can have only one server for a user. There are corresponding checks through Mutex. Those. I do not see the difference whether it is a random name or a static user prefix. And what this prefix should be? - Sergej Loos
  • what this prefix should be? Identifying application. So that no one is confused ... 'MySuperPuperServer' - will do. You will watch all the pipes - you will immediately understand where this one came from. Again, it will be easier for the client to find the right pipe or check himself that he was not mistaken in his choice (and at the same time you can verify the account - your own and the server by PID - on whose behalf the process is started to make sure that this is your server). And yes, the prefix is ​​not needed. - Akina

0