By the way I realize that I was just asking about bluetooth, This app has both bluetooth and wifi sharing. pretty standard feature set I suppose. I did simi solve the problem I've been having with this by turning off the send and receive structure. In other words when a session starts it does not automatically exchange data the data only goes one way which is direct contrast to what I was wanting to do. if some one could point me in the right direction for doing an exchange it would really help.

On Sep 15, 2009, at 2:36 PM, Development wrote:

Ok I have reused this code a million times and never had a problem until now.

I'm attempting to send an NSDictionary from one iPhone to another. Actually an iPod to the simulator. And one of two things happens. Either the data is totally muxed Meaning sent completely out of order OR it sends the data in order, but does it twice on the same connection just out of phase with one another so the incoming data is mixed up. Below is my send and receive code: O and I got the bright idea to send the NSDictionary after packaging it using NSKeyedArchiver but unfortunately that results in crashes due to 'Incomprehensible archive' errors.


- (void) sendData:(NSData*)dataToSend
{

   if (_outStream) {
       unsigned remainingToWrite = [dataToSend length];
       void * marker = (void *)[dataToSend bytes];
       while (0 < remainingToWrite) {
           int actuallyWritten = 0;
actuallyWritten = [_outStream write:marker maxLength:remainingToWrite];
           remainingToWrite -= actuallyWritten;
           marker += actuallyWritten;
       }
        }


}
                case NSStreamEventHasBytesAvailable:
                {
                        if (stream == _inStream) {
NSMutableData * dataBuffer = [[NSMutableData alloc]init/ *WithCapacity:(100*1024)*/];
                                if(!cardData) cardData = [[NSMutableData 
alloc]init];
                                uint8_t buf[16 * 1024];
                                uint8_t *buffer = NULL;
                                unsigned int len = 0;

                                while ((NSInputStream*)[stream 
hasBytesAvailable])
                                {
                                        NSLog(@"In comming");
                                        if (![(NSInputStream*)stream 
getBuffer:&buffer length:&len]) {
int amount = [(NSInputStream*)stream read:buf maxLength:sizeof (buf)];
                                                buffer = buf;
                                                len = amount;
                                        }
                                        if (0 < len) {
                                                if (!dataBuffer) {
                                                        dataBuffer = 
[[NSMutableData alloc] init];
                                                }
                                                [dataBuffer appendBytes:buffer 
length:len];
                                                [cardData 
appendData:dataBuffer];
                                        }
                                }

NSString * string = [[NSString alloc]initWithCString: [dataBuffer bytes]];
                                        if ([string 
rangeOfString:@"Ready"].length) {
                                                [self sendCard];
                                        }
                                        else{
                                                gotcard = YES;
                                                [delegate decodeCard:cardData 
fromCommunicator:self];
                                                [cardData release];
                                                cardData = nil;
                                        }
                        
                        }
                        
                        break;
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/development%40fornextsoft.com

This email sent to developm...@fornextsoft.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to