Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by EKovalev · Mar 13, 2013 at 07:20 PM · c#freezestreampipe

Using Pipes/Streams Freezes Unity

Hello,

So I'm trying to get two processes to communicate with each other. Specifically a Visual C# Program that does something and sends strings through the pipe as it does it, and a Unity C# script which receives those messages. The problem is that unity, whenever I run this script (Included below) freezes and nothing happens. For the sake of testing there is an empty Unity Game Object that only has the script in it.

If anyone knows anything about this problem, or can help me out, that would be very helpful. I'm using these programs from MSDN for reference on how to communicate using Pipes in C#: http://msdn.microsoft.com/en-us/library/bb546102.aspx

 using UnityEngine;
 using System.Collections;
 using System.IO;
 using System.IO.Pipes;
 using System.Diagnostics;
 
 public class iPhoneCommunicator : MonoBehaviour {
     Process pipeClient;
     AnonymousPipeServerStream pipeServer;
     
     public void Start(){
         Console.WriteLine("Hello, World!");
         pipeClient = new Process();
         // Point the program to the executable
         pipeClient.StartInfo.FileName = "C:\\Users\\Eugene\\Briefcase\\School Documents\\CSE 4904 - Senior Design\\src\\TeamB-Code\\AirControl\\AirControlServerWindows\\AirControlServerAlpha\\bin\\Debug\\AirControlTest.exe";
         // Initialize the Server Stream
         pipeServer = new AnonymousPipeServerStream(PipeDirection.In,HandleInheritability.Inheritable);
         //Set Transmission mode to bytes, since messages are not accepted
         pipeServer.ReadMode = PipeTransmissionMode.Byte;
         // Pass the client process a handle to the server.
         pipeClient.StartInfo.Arguments = pipeServer.GetClientHandleAsString();
         // Disable Console output for the client
         pipeClient.StartInfo.UseShellExecute = false;
         // Start the client
         pipeClient.Start();
         pipeServer.DisposeLocalCopyOfClientHandle();
     }
     public void Update(){
         Console.WriteLine("Updating");
         using (StreamReader sr = new StreamReader(pipeServer))
         {
             // Display the read text to the console 
             string temp;
 
             // Wait for 'sync message' from the server. 
             //Synchronize with the client, wait for a "SYNC" message 
             do
             {
                 Console.WriteLine("[SERVER] Wait for sync...");
                 temp = sr.ReadLine();
             }
             while (!temp.StartsWith("SYNC"));
 
             // Read the server data and echo to the console. 
             while ((temp = sr.ReadLine()) != null)
             {
                 Console.WriteLine("[SERVER] Echo: " + temp);
             }
         }
     }
 }
 
 public static class Console {
     public static void WriteLine(System.Object obj){
         UnityEngine.Debug.Log(obj.ToString());    
     }
     public static void WriteError(System.Object obj){
         UnityEngine.Debug.LogError(obj.ToString());    
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Summit_Peak · Jan 02, 2017 at 05:12 PM

DisposeLocalCopyOfClientHandle() throws an error. The only option is to comment this line out.

GetClientHandleAsString() returns an integer in string format ("17116"), but the constructor on the client side cannot connect to this handle:

 //pipe = new AnonymousPipeClientStream(PipeDirection.In, Environment.GetCommandLineArgs()[0]);
 pipe = new AnonymousPipeClientStream(PipeDirection.In, "17116");

With no connection, the code gets stuck forever on this line: temp = sr.ReadLine();

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ReadLine from Named Pipe freezes Unity 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Keep distance using NavMeshAgent causing freeze. 1 Answer

Aqueducts connecting. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges