Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9017081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:10:24+00:00 2026-06-16T04:10:24+00:00

I need to realize a communication between two threads using NSPipe channels, the problem

  • 0

I need to realize a communication between two threads using NSPipe channels, the problem is that I don’t need to call terminal command by specifying this methods.

[task setCurrentDirectoryPath:@"....."];
[task setArguments:];

I just need to write some data

NSString * message = @"Hello World";
[stdinHandle writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];

and on the other thread to receive this message

NSData *stdOutData = [reader availableData];
NSString * message = [NSString stringWithUTF8String:[stdOutData bytes]]; //My Hello World

For example such things in C# can be easy done with NamedPipeClientStream, NamedPipeServerStream classes where pipes are registered by id string.

How to achieve it in Objective-C?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:10:25+00:00Added an answer on June 16, 2026 at 4:10 am

    If I understand your question correctly, you can just create a NSPipe and use one end for reading and one end for writing. Example:

    // Thread function is called with reading end as argument:
    - (void) threadFunc:(NSFileHandle *)reader
    {
        NSData *data = [reader availableData];
        NSString *message = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"%@", message);
    }
    
    - (void) test
    {
        // Create pipe:
        NSPipe *pipe = [[NSPipe alloc] init];
        NSFileHandle *reader = [pipe fileHandleForReading];
        NSFileHandle *writer = [pipe fileHandleForWriting];
    
        // Create and start thread:
        NSThread *myThread = [[NSThread alloc] initWithTarget:self
                                                     selector:@selector(threadFunc:)
                                                       object:reader];
        [myThread start];
    
        // Write to the writing end of pipe:
        NSString * message = @"Hello World";
        [writer writeData:[message dataUsingEncoding:NSUTF8StringEncoding]];
    
        // This is just for this test program, to avoid that the program exits
        // before the other thread has finished.
        [NSThread sleepForTimeInterval:2.0];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to realize a complex if-elif-else statement in Python but I don't get
I realize that I need to use a mailserver so people can contact me,
I need to realize a WebSite with a grid that shows all items of
it seems a trivial point, until you realize that you need consistency. Not being
i've been stuck with this problem for a while. I need to realize a
I didn't realize at the time I create this particular application that I'd need
I need to realize a following authentication on my asp.net: the user on the
Developing a project of mine I realize I have a need for some level
I'm running a long simulation in MATLAB that I've realized I need to stop
Using visual studio 2008, I had a solution open and realized I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.