login about faq

Using ChilKat sockets we have an app that transfer data over a socket connection. Most pieces will be split into chunks so the socket is sending/receiving a set number of bytes. ie

[_socket SendBytes:dataChunk numBytes:[NSNumber numberWithInteger:chunkLength]]


NSData *data = [_socket ReceiveBytesN:[NSNumber numberWithInteger:chunkSize]];

As this could be a long running operation we have found that we also need to pass messages between instances of the application while the data transfer is ongoing. So what would make sense would be to set up an async socket on all instances that are both listening for messages but are also able to send messages. The thinking was something like this running on both server instance and client instance:

    - (void) startComms {

    while (YES) {
        if ([_commsSocket AsyncReceiveUntilMatch:@"-EOM-"]) {
            while (![_commsSocket AsyncReceiveFinished]) {
                [_commsSocket SleepMs:[NSNumber numberWithInt:100]];
            if ([_commsSocket AsyncReceiveSuccess]) {
                NSLog(@"Received string: %@", _commsSocket.AsyncReceivedString);
            else {
                NSLog(@"Comms failed");
        else {
            NSLog(@"failde to receive until match\n%@", _commsSocket.LastErrorText);

- (void) sendComm:(NSString *) message {

    if (![_commsSocket AsyncSendString:[message stringByAppendingString:@"-EOM-"]]) {
        NSLog(@"send err %@", _commsSocket.LastErrorText);

    while (!_commsSocket.AsyncSendFinished) {
        [_commsSocket SleepMs:[NSNumber numberWithInt: 100]];

    if (!_commsSocket.AsyncSendSuccess != YES) {
        NSLog(@"send success err %@", _commsSocket.AsyncSendLog);

Is this the way to go about it? How can we establish this second socket connection between the connected pair?

asked Mar 06 '13 at 07:59

Dan's gravatar image


Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Mar 06 '13 at 07:59

Seen: 1,801 times

Last updated: Mar 06 '13 at 07:59

powered by OSQA