Discussion:
how to pass objects thru NamedPipes
(too old to reply)
Villu
2008-12-05 16:51:01 UTC
Permalink
Hi..

I was able to pass string messages in NamedPipes, for communicating between
two running exes, but I actually want to pass objects.

The steps I used to send string message from server exe to client exe

I created Named Pipe in the server exe using

NamedPipeServerStream objPipe = new NamedPipeServerStream("MyPipeName",
PipeDirection.Out,
1,
PipeTransmissionMode.Message,
PipeOptions.Asynchronous,
BUFFER_SIZE,
BUFFER_SIZE);


I write into the pipe using...

StreamWriter objWriter = new StreamWriter(objPipe);
objWriter.WriteLine("Message to client");



Now, in the client... I connected to the pipe server pipe using....

NamedPipeClientStream objPipe = new NamedPipeClientStream(".",
"MyPipeName",
PipeDirection.InOut,
PipeOptions.Asynchronous);
objPipe .Connect();
objPipe .ReadMode = PipeTransmissionMode.Message;


I read from the pipe using

byte[] buffer = new byte[BUFFER_SIZE];
ObjPipe.Read(buffer, 0, buffer.Length));

Can anyone help me to change this to pass objects instead of a string
message between the exes

I got the code from article
http://blog.benday.com/archive/2008/06/22/23182.aspx

- villu
lallous
2009-01-13 18:38:46 UTC
Permalink
Hello

I am not a .net expert, perhaps there is a way to directly pass objects,
nonetheless, since you can pass strings, you could use it to pass objects:

sender:
1. serialize object into a string
2. send the object as the serialized string

receiver:
1. receive serialize object as string
2. deserialize back into an object

HTH,
Elias
Post by Villu
Hi..
I was able to pass string messages in NamedPipes, for communicating between
two running exes, but I actually want to pass objects.
The steps I used to send string message from server exe to client exe
I created Named Pipe in the server exe using
NamedPipeServerStream objPipe = new NamedPipeServerStream("MyPipeName",
PipeDirection.Out,
1,
PipeTransmissionMode.Message,
PipeOptions.Asynchronous,
BUFFER_SIZE,
BUFFER_SIZE);
I write into the pipe using...
StreamWriter objWriter = new StreamWriter(objPipe);
objWriter.WriteLine("Message to client");
Now, in the client... I connected to the pipe server pipe using....
NamedPipeClientStream objPipe = new NamedPipeClientStream(".",
"MyPipeName",
PipeDirection.InOut,
PipeOptions.Asynchronous);
objPipe .Connect();
objPipe .ReadMode = PipeTransmissionMode.Message;
I read from the pipe using
byte[] buffer = new byte[BUFFER_SIZE];
ObjPipe.Read(buffer, 0, buffer.Length));
Can anyone help me to change this to pass objects instead of a string
message between the exes
I got the code from article
http://blog.benday.com/archive/2008/06/22/23182.aspx
- villu
Loading...