Hi
I am trying to use named pipes in Unity to pass data to and from another application.
I made test Pipe Server in VS2012
static void Main(string[] args)
{
CreatingPipeServerLoop();
}
const byte sentServerValue = 1;
const byte sentClientValue = 2;
static public void CreatingPipeServerLoop()
{
while (true)
{
Thread.Sleep(500);
using (NamedPipeServerStream pipeServer =
new NamedPipeServerStream("pipetest", PipeDirection.InOut))
{
pipeServer.WaitForConnection();
Console.WriteLine("Client connected.");
try
{
byte answer = (byte)pipeServer.ReadByte();
pipeServer.WriteByte(sentServerValue);
pipeServer.Flush();
}
catch (Exception e)
{
Console.WriteLine("ERROR: {0}", e.Message);
}
}
}
}
And I made Pipe Client in Unity3d 5.1.2f1 :
void Start () {
System.Threading.Thread pipeThread = new System.Threading.Thread(delegate() { CreatingPipeClientLoop(); });
pipeThread.Start();
}
// Update is called once per frame
void Update () {
}
const byte sentServerValue = 1;
const byte sentClientValue = 2;
public void CreatingPipeClientLoop()
{
for (int i = 0; i < 100000; i++)
{
//byte respByte = 0;// MainBaseErrorExcess;
using (NamedPipeClientStream pipeClient =
new NamedPipeClientStream("pipetest"))
{
try
{
pipeClient.Connect();
//Console.WriteLine("Server connected.");
pipeClient.WriteByte(sentClientValue);
pipeClient.Flush();
byte respByte = (byte)pipeClient.ReadByte();
}
catch (System.Exception e)
{
//Console.WriteLine("ERROR: {0}", e.Message);
}
}
}
}
I started Server and then Client in Unity3d 5.1.2f1. Server connected 1-2 times then Unity crashed. Some times pipeClient threw exception "The operation completed successfully".
I launched this test project on 5 PC with Windows 7 (64 bit) every time Unity crashed. It worked only on PC with Windows 7 (32 bit) and Windows 7 on Mac. Also it worked in Unity 4.5, befor I updated Unity I did not know about the problem. How to implement exchange between Unity and another application?
Regards, Anatoly Frolkin.
↧