我有一个像这样创建的 c# namedpipe 服务器:
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);
}
像上面那样写出小字符串没有问题。 然而,当我开始发出巨大的字符串时,例如 1500 个字符,管道挂起并保持挂起状态,直到我杀死它试图向其发送内容的客户端。客户端是一个java应用程序。 我看到这是向客户端发送内容,之后发生挂起。
客户端是一个 Java 应用程序,接收以下内容:
RandomAccessFile pipe = new RandomAccessFile("\\\\.\\pipe\\mypipe", "rw");
while(true)
{
String received = pipe.readLine();
processEvent(received);
System.out.println("Response: " + received );
}
客户端没有抛出异常,我可以在readline()之后看到System.out。 那么是什么给了?
最佳答案
呸!就我而言,这纯粹是愚蠢的。 好像有什么东西卡在里面
processEvent(received);
我还以为是
System.out.println("Response: " + received );
但事实并非如此。 processEvent(...) 有一个重复的 System.out.println("Response: "+ received );
在里面,因此我很困惑。
毕竟它与命名管道无关。
谢谢大家 =)
关于c# - Namedpipe 在发送大字符串时挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8347790/