Note that there are some explanatory texts on larger screens.

plurals
  1. POSwitch from Sockets to cocoaasyncsockets (question related to string conversion)
    text
    copied!<p>This question is related to a iOS project written in ObjectiveC that makes use of some C++-Headers.</p> <p>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. </p> <pre><code>-(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&lt;len; ++i) { test[i] = out_[i]; } [outputStream write:test maxLength:len]; } </code></pre> <p>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?</p> <p>This is what writing to a server using this framework looks like:</p> <pre><code>NSString *warningMsg = @"Are you still there?\r\n"; NSData *warningData = [warningMsg dataUsingEncoding:NSUTF8StringEncoding]; [sock writeData:warningData withTimeout:-1 tag:WARNING_MSG]; </code></pre> <p>These are the definitions of the two methods used for encoding and decoding</p> <pre><code>unsigned int decode(const char* string, unsigned int len, char* out); unsigned int encode(const char* string, unsigned int len, char* out); </code></pre> <p>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.</p> <p>What is the best way to deal with this kind of conversion to achieve the same result using this framework?</p> <p>Thanks in advance for your answers and time spent!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload