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); }
'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