• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Messaging System
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Messaging System


  • Subject: Messaging System
  • From: Gordon Apple <email@hidden>
  • Date: Tue, 09 Nov 2010 11:56:03 -0600
  • Thread-topic: Messaging System

We are using code based on the WiTap example, but sending messages of
varying length, all less than a few hundred bytes, from iPhone to iPad. We
are attempting to always send an NSData object. Here is a skinnied-down
example.

We know the overall connection works.  Unfortunately, we are not getting the
buffer pointer, length shows 0, and "success" returns NO ("buffer not
available"), so "parseMessage is not getting called.  I'm not sure what
"buffer not available" means.  Messages are short enough that they shouldn't
be split.  What are we doing wrong?

Send:

- (void) send:(const uint8_t*)message maxLength:(NSUInteger)numBytes {
    [self.rc send:message maxLength:numBytes];
}

- (void)sendType:(NSString*)type name:(NSString*)name {
    NSMutableData* data = [NSMutableData data];
    NSKeyedArchiver* arch = [[NSKeyedArchiver alloc]
initForWritingWithMutableData:data];
    [arch encodeObject:type forKey:kMessageTypeKey];
    [arch encodeObject:name forKey:kMessageNameKey];
    [arch finishEncoding];
    [arch release];
    [self send:(uint8_t*)data maxLength:[data length]];
}

- (void)sendActionName:(NSString*)name {
    [self sendType:kMessageTypeAction name:name];
}

Receive:

- (void)parseMessage:(NSData*)data {
    NSKeyedUnarchiver* unArch = [NSKeyedUnarchiver
unarchiveObjectWithData:data];
    NSString* type = [unArch decodeObjectForKey:kMessageTypeKey];
    NSString* name = [unArch decodeObjectForKey:kMessageNameKey];

    if ([type isEqualToString:kMessageTypeAction]) {
        if ([name isEqualToString:@"startStopButtonHit"]) {
            pvc.startStopButtonHit;
        }
    }
}

- (void)handleMessage:(NSInputStream *)stream {
    uint8_t* buffer = nil;
    NSUInteger len = 1024;  //  Doesn't matter what it is.  Gets set to 0.

    BOOL success;
    success = [stream getBuffer:&buffer length:&len];
    if(success) {
        NSData* data = nil;
        data = [NSData dataWithBytes:(const void *)buffer length:len];
        [self parseMessage:data];
    }
}



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Messaging System
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
  • Prev by Date: NSURLConnection: Difference between iOS 3.2 and 4.1?
  • Next by Date: Re: Messaging System
  • Previous by thread: NSURLConnection: Difference between iOS 3.2 and 4.1?
  • Next by thread: Re: Messaging System
  • Index(es):
    • Date
    • Thread