2012-03-14 88 views
0

我有Windows服务,使它从TCP连接接收数据,然后通过命名管道立即发送相同的数据到Web服务。任何人都可以建议我如何设置管道,以便我连接一次到管道,然后对所有传入连接使用相同的管道。NamedPipeClientStream一次性连接

这是我的窗口服务代码部分:

pipeStream = new NamedPipeClientStream(".", pipename, PipeDirection.Out); 
    while (true) 
     { 
      byte[] data = new byte[100]; 
      int recv = newTCP.Receive(data, ref tmpRemote); 
      try 
      { 
       pipeStream.Connect(3); 
       pipeStream.Write(data,0,recv); 
     } 
+0

WHH你不动'pipeStream.Connect(3);'所在的地方你创建'NamedPipeClientStream' – 2012-03-14 21:44:40

+0

关于这个类的更多细节包括管道声明。 – 2012-03-14 21:44:49

回答

0

移动pipeStream.Connect(3);在真正的时刻之前; 所以,现在你有可以反复使用的文字流。 现在,以后每写,如果你想要的数据马上去,请确保调用flush方法:

pipeStream = new NamedPipeClientStream(".", pipename, PipeDirection.Out); 
pipeStrea.Connect(3); 
while(true) 
{ 
    ... // Get your TCP data 
    pipeStream.Write(data,0,recv); 
    pipeStream.Flush();