Glstunna Glstunna - 5 months ago 28
Java Question

Namedpipe hangs when sending large string

I have a c# namedpipe server created like so:

NamedPipeServerStream pipeServer = new NamedPipeServerStream(IVConstants.PIPENAME, PipeDirection.InOut);
pipeServer.WaitForConnection();
pipeWriter = new StreamWriter(pipeServer);
pipeWriter.AutoFlush = true;

try
{
pipeWriter.WriteLine("You are Connected!!!");
}
catch (IOException e)
{
Console.WriteLine("ERROR: {0}", e.Message);
}


Writing out small strings like the one above gives no problem.
However when I start chugging out huge strings e.g 1500 chars, the pipe hangs and stays hung until I kill the client it is trying to send something to. The client is a java app.
I see that is DOES send stuff to the client, after-which the hang happens.

The client is a Java app receiving with this:

RandomAccessFile pipe = new RandomAccessFile("\\\\.\\pipe\\mypipe", "rw");

while(true)
{
String received = pipe.readLine();
processEvent(received);
System.out.println("Response: " + received );
}


The client doesn't throw an exception, and I can see the System.out after the readline().
So what gives?

Answer

Bah! Pure foolishness on my part. It seems something was hanging in

processEvent(received);

I thought it was getting to

System.out.println("Response: " + received );

But it wasn't. processEvent(...) had a duplicate System.out.println("Response: " + received ); in it, hence my confusion. It had nothing to do with the namedpipe after-all.

Thanks guys =)