named-pipe-wrapper icon indicating copy to clipboard operation
named-pipe-wrapper copied to clipboard

PushMessage in the client doesn't seem to work

Open PatrLind opened this issue 7 years ago • 2 comments

I cannot get the PushMessage() function in the client to send anything to the server. Client is doing something like this:

                    var pipeClient = new NamedPipeClient<IpcInfo>(pipeName);
                    pipeClient.Start();
                    pipeClient.WaitForConnection();
                    var message = new IpcInfo();
                    pipeClient.PushMessage(message);
                    pipeClient.WaitForDisconnection();
                    pipeClient.Stop();

Server like this:

                    var pipeServer = new NamedPipeServer<IpcInfo>(pipeName);
                    pipeServer.ClientConnected += delegate (NamedPipeConnection<IpcInfo, IpcInfo> conn)
                    {
                    };

                    pipeServer.ClientMessage += delegate (NamedPipeConnection<IpcInfo, IpcInfo> conn, IpcInfo message)
                    {
                        conn.Close();
                    };
                    var application = new App();
                    application.InitializeComponent();
                    pipeServer.Start();
                    application.Run();
                    pipeServer.Stop();

I get a callback for ClientConnected, but not in ClientMessage. Client is waiting for disconnect.

PatrLind avatar Jun 19 '17 04:06 PatrLind

I had this problem. I created the same serializable class in each project, however this generates two distinct classes. I created a 3rd project called data and put my message classes in there and referenced it from both the client and server project and was then able to communicate as expected.

You should be able to see the error you're getting if you add a handler for pipeServer.Error and print the exception to the screen.

EDIT: I just cloned the most current repo, and it does appear that the PushMessage does not work.

EDIT2: Even stranger, if I step through the code, the message does send, if I don't step through, I get the ClientConnected but not the ClientMessage.

EDIT3: DO NOT CALL pipeClient.Stop immediately after PushMessage, this seems to kill the thread before it can complete. Not sure why you're having problems if you're calling WaitForDisconnection though.

lempface avatar Aug 30 '17 19:08 lempface

You have distint classes because of the base namespace (you can change in the project properties) that is the name of the project. It happens event with WCF.

FilRav avatar Oct 16 '18 13:10 FilRav