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 6124755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:10:08+00:00 2026-05-23T16:10:08+00:00

This question is related to a iOS project written in ObjectiveC that makes use

  • 0

This question is related to a iOS project written in ObjectiveC that makes use of some C++-Headers.

I’m using this method to send messages to a server using TCP. As you can see, there is a c++ method called that modifies the string to conform to a specific protocol. This string is written to a stream.

-(void) writeToServer:(NSString*) str 
{   
    int len = [str length];
    const char* in_ = new char[len];
    char* out_ = new char[len];

    in_ = [str UTF8String];

    len = binary8BitStringTo7BitStringEncoding::encode(in_, len, out_);

    uint8_t* test = new uint8_t[len];

    for (int i=0; i<len; ++i) {
        test[i] = out_[i];
    }

    [outputStream write:test maxLength:len];
}

I’m planning to use the cocoaasyncsocket-framework (http://code.google.com/p/cocoaasyncsocket/) instead of dealing with streams directly. Question is: How to achive the same functionality when using this framework?

This is what writing to a server using this framework looks like:

NSString *warningMsg = @"Are you still there?\r\n";
NSData *warningData = [warningMsg dataUsingEncoding:NSUTF8StringEncoding];
[sock writeData:warningData withTimeout:-1 tag:WARNING_MSG];

These are the definitions of the two methods used for encoding and decoding

unsigned int decode(const char* string, unsigned int len, char* out);
unsigned int encode(const char* string, unsigned int len, char* out);

In fact i’m looking for a way to send the char* (result of the encode method) to the server but i’m unsure about the whole”NSString* to char* to uint8_t* to NSString* conversion.

What is the best way to deal with this kind of conversion to achieve the same result using this framework?

Thanks in advance for your answers and time spent!

  • 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-05-23T16:10:09+00:00Added an answer on May 23, 2026 at 4:10 pm

    I figured it out, the equivalent method looks like this:

    -(void) writeToServer:(NSString*) str{
    
        int len = [str length];
        const char* in_ = new char[len];
        char* out_ = new char[len];
    
        in_ = [str cStringUsingEncoding:NSASCIIStringEncoding];
    
        len = binary8BitStringTo7BitStringEncoding::encode(in_, len, out_);
    
        [socket writeData:[NSData dataWithBytes:out_ length:len] withTimeout:-1 tag:1];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Related to my precedent question error when using a bundle in an iOS project
(This question is related to another one , but different enough that I think
This question is related to UITableView issue when using separate delegate/dataSource , though I
This question is related to another question that I posted on SO earlier How
This question is related to my previous question Link The method bellow does excatly
This question is related to (but perhaps not quite the same as): Does Django
This question is related to another question which I asked yesterday! List all links
This question is related to a previous post of mine Here . Basically, I
[This question is related to but not the same as this one .] My
This question is related to this one , though I think I was a

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.