- Home /
Pipestream async operations disconnect server(?)
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!
Answer by Razia Mahmood · Jul 21, 2015 at 03:54 PM
All i know is Unity3D uses .Net 3.5 which don't support asynchronous operations. From some fourm Someone refer to download Microsoft Reactive Extensions and add those libraries as references. http://stackoverflow.com/questions/5050004/system-threading-tasks
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Feature 'async function' is not available in C# 4 2 Answers
Flip over an object (smooth transition) 3 Answers
Creating piping model at runtime 0 Answers