Quantcast
Channel: Questions in topic: "pipe"
Viewing all articles
Browse latest Browse all 89

Pipestream async operations disconnect server(?)

$
0
0
Hi there! I am working on a game that uses pipes to transmit some data from one process to another, and it all works perfectly when I use blocking operations (e.g. NamedPipeServerStream.Connect) but when I use their asynchronous variants (NamedPipeServerStream.BeginWaitForConnection) the pipe gets disconnected and throws an "operation completed" exception I have tested my code in my other application which runs on .NET 4.5 and it works fine there. Code: NamedPipeServerStream _pipeServer; NamedPipeClientStream _pipeClient; void WaitForConnectionCallback(IAsyncResult result) { try { _pipeServer.EndWaitForConnection(result); Debug.Log("Connected"); } catch (Exception ex) { Debug.Log("WaitForConnectionCallback Exception: " + ex); } } void StartServer() { try { Debug.Log("Creating pipe server"); _pipeServer = new NamedPipeServerStream(@"\\.\pipe\localPipe", PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); Debug.Log("Waiting for connections"); _pipeServer.BeginWaitForConnection(WaitForConnectionCallback, null); Debug.Log("Creating pipe client"); _pipeClient = new NamedPipeClientStream(".", @"\\.\pipe\localPipe", PipeDirection.In, PipeOptions.Asynchronous); Debug.Log("Connecting pipe client"); _pipeClient.Connect(100); Thread.Sleep(1000); Debug.Log("Cleaning up server"); if (_pipeServer.IsConnected) _pipeServer.Disconnect(); _pipeServer.Close(); _pipeServer.Dispose(); Debug.Log("Cleaning up client"); _pipeClient.Close(); _pipeClient.Dispose(); } catch (Exception ex) { Debug.Log("StartServer Exception: " + ex); } } Anyone know a fix? Thanks in advance!

Viewing all articles
Browse latest Browse all 89

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>