Reputation: 3275
I'm encountering a strange problems with Named pipes on Windows in C#.
Client:
NamedPipeClientStream pipeStream = new NamedPipeClientStream("default-PC","mypipe");
pipeStream.Connect();
BinaryWriter sw = new BinaryWriter(pipeStream);
sw.Write((byte[]) data);
Server:
NamedPipeServerStream pipeStream = new NamedPipeServerStream("mypipe");
byte[] dataAll = null;
pipeStream.WaitForConnection();
dataAll = new BinaryReader(pipeStream).ReadBytes(1024 * 1000 * 512);
--
If I use "." as a server name in the constructor for the NamedPipeClientStream everything works correctly, i.e. the server fills the dataAll object.
Now the strange thing is that if I on the other hand put the network name of the computer("default-PC") in the NamedPipeClientStream like shown in the code above then no data is read on the server as ReadBytes in the server code returns an empty array.
This could understandable I was running the server and client on two different computers but they are both running on the same machine. The only difference being whether the "server name" parameter in NamedPipeClientStream is "." or the actual network name (or even localhost).
Any ideas?
Upvotes: 0
Views: 6517
Reputation: 3275
So the conclusion is this:
If the Server name parameter in NamedPipeClientStream is something else than "." then the underlying implementation is through a transport layer that supports a maximum of 64k in a single Write operation. The problem is that if you Write more than 64k then the data just disappears instead of throwing an exception.
The solution is to use the NamedPipeClientStream directly and Write the data in less than 64kb chunks.
Upvotes: 1
Reputation: 2146
I believe that both "." and "localhost" are considered special names and don't use the normal network connections, but a loopback of some sort.
When you specify a computer name, even your own computer's name, it uses the standard network protocols/stack/etc.
You probably need to open a firewall port. TCP 445. Also, by default, Windows allows all outgoing communications. You should only need to add an inbound port exception. Your configuration may vary of course. .NET 3.5 (C#) Named pipes over network
Upvotes: 2