Hello,
I've been trying to used named pipes in order to send data from one application to Unity, and I was thinking that named pipes would be a good idea. However, whenever I try creating the Server, I get a win32exception error so that apparently the server is never created. I can create the client, I believe, because I get a NamedPipeClientStream object with no errors, and then when I try using pipe.Connect() I get the same excact win32 error. This is probably because there is no established server to connect to.
My confusion is why I can create the client, but not the server? The syntax for both seems to be the same in its documentation. Here are both the examples I ran, and the reason I am using so many namespaces is because this is part of a larger chunk of code, but maybe the other namespaces are interfering with the pipe declaration.
PipeServerTest.cs:
using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.IO.Pipes;
using System.Text;
using System.Threading;
using System.ComponentModel;
public class PipeServerTest : MonoBehaviour {
// Use this for initialization
void Start () {
try{
NamedPipeServerStream pipeServer = new NamedPipeServerStream("testpipe"){
print (pipeServer);
}
catch(Win32Exception w){
print(w.Message);
print(w.ErrorCode.ToString());
print(w.NativeErrorCode.ToString());
print(w.StackTrace);
print(w.Source);
Exception e=w.GetBaseException();
print(e.Message);
}
}
}
PipeClientTest.cs:
using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.IO.Pipes;
using System.Text;
using System.Security.Principal;
using System.Diagnostics;
using System.Threading;
using System.ComponentModel;
public class PipeClientTest : MonoBehaviour {
// Use this for initialization
void Start(){
NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", "testpipe", PipeDirection.InOut);
print (pipeClient);
try{
pipeClient.Connect();
}
catch(Win32Exception w){
print(w.Message);
print(w.ErrorCode.ToString());
print(w.NativeErrorCode.ToString());
print(w.StackTrace);
print(w.Source);
Exception e=w.GetBaseException();
print(e.Message);
}
}
}
I'd also like to note that I'm not sure if this should go in a Start() function. When I use Main() I get no outputs... or maybe that's intended.
[Reference to named Pipes][1]
[1]: http://msdn.microsoft.com/en-us/library/bb546085.aspx
↧