Rob Smyth

Tuesday, 7 October 2008

NamedPipeClientStream Gotcha

I've been playing with the .Net 3.5 NamedPipeClientStream for NUnitGridRunner and had been testing my application at home on my portable, but when I moved to cafe I found that my application threw excetpions. The difference was that even though I wasd running both client and server on the one box, the bahaviour changes depending if I have a network.

As a result the code ended up like this:

public void Start()
{
string hostName = Environment.MachineName.ToLower() == gridHostName.ToLower()
? "."
: gridHostName;

pipeClient = new NamedPipeClientStream(hostName, "NUnitGrid", PipeDirection.InOut,
PipeOptions.Asynchronous);
}

1 comment:

Greg said...

This feels like a PipeClientFactory.

What I mean is the bulk of this code could go into a factory class and then be used by the Start method. i.e.
pipeClient = PipeClientFactory.Get();

or something similar.

James