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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:10:10+00:00 2026-05-27T19:10:10+00:00

I am trying to send a dictionary of information from one iphone to another

  • 0

I am trying to send a dictionary of information from one iphone to another iphone through wifi/blutooth,for that i implement CFnetwork and NSNetservice Concept.I received Data in the Reciver side.

I did code as follows ….

**Sender Side**

 samDict=[NSMutableDictionary dictionary];
     [samDict setObject:@"Muhammed Musthafa" forKey:@"PP"];
     [samDict setObject:@"John P" forKey:@"Jose"];
     [samDict setObject:@"Lubaba" forKey:@"P"];
     [samDict setObject:@"JINI" forKey:@"KS"];
     [samDict setObject:@"Anusha" forKey:@"GS"];
     [samDict setObject:@"Athulya" forKey:@"V"];
     [samDict setObject:@"Riyas" forKey:@"MM"];
     [samDict setObject:@"Raihanath" forKey:@"MH"];
     [samDict setObject:@"Shabeer" forKey:@"poola"];
     [samDict setObject:@"Rajisha" forKey:@"Raji"];

     //NSLog(@" Dictionary values.............%@",samDict);

    NSMutableData *ArchiveData=[[NSMutableData alloc]init];    
    NSKeyedArchiver *archiver=[[NSKeyedArchiver alloc]initForWritingWithMutableData:ArchiveData];
    [archiver setOutputFormat: NSPropertyListXMLFormat_v1_0];

    [archiver encodeObject:self.samDict forKey:@"Some Key Values"];
    [archiver finishEncoding];    
    [archiver release];

    const uint8_t *buffer=(const uint8_t *)[ArchiveData bytes];
    NSInteger nWrtitten=[_outStream write:buffer maxLength:[ArchiveData legth]];
    if (!nWrtitten)
    {
        NSLog(@"Eorror writting to Stream %@ : %@", _outStream, [_outStream streamError]);
    }
    else
    {

        NSLog(@" Write %ld bytes to Stream %@",(long)nWrtitten, _outStream);
    }

Receiver side

 NSInteger bytesRead;
        uint8_t buffer[13000];
        NSMutableData *data=[[NSMutableData data]retain];           

        if (stream==_inStream)
        {


            bytesRead=[_inStream read:buffer maxLength:sizeof(buffer)];
            if (bytesRead==-1&& bytesRead==0)
            {
                NSLog(@"_inStream Error...................");
            }
            else
            {                                       
                [data appendBytes:buffer length:bytesRead];
                NSLog(@"Data Received has length   :%d\n\n",[data length]);

                NSLog(@"data............%@",data);

            }
        }

I got data in Receiver Side.that is in bytes format . I can’t UnArchive this data in Receiver side.if i am trying to unarchived this to Dictionary format like this

NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
   NSMutableDictionary* UnArchiveDictionary =[NSMutableDictionary dictionary];
    UnArchiveDictionary = [[unarchiver decodeObjectForKey:@"Some Key Values"] retain]; 
    NSLog(@"UnArchive Dictionary  %@",UnArchiveDictionary);  

But unfortunately ican’t Unarchived this data in Dictionary Format. i am getting Error of line NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];

I have found some code for that converting bytes Data to String Format like this

size_t length=[data length];
                    unsigned char aBuffer[length];
                    [data getBytes:aBuffer length:length];
                    aBuffer[length - 1]=0;
                    NSString *messageString =aBuffer; 

                    NSLog (@"%s",messageString);

But my problem is how to get back the same dictionary . Why getting error in Unarchived time?

  • 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-27T19:10:11+00:00Added an answer on May 27, 2026 at 7:10 pm

    The problem might be that the condition:

    if (bytesRead==-1&& bytesRead==0)
    

    will always be false. A variable can’t have two different values at once. You probably want:

    if (bytesRead==-1 || bytesRead==0)
    

    So if there was an error (or no data was transmitted) your code wouldn’t notice and instead append garbage bytes from the stack to your mutable data.

    The keyed unarchiver then tries to interpret these garbage bytes as an archive and notices that it isn’t, so it throws an exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send form data from one page to another using C#
Im trying to send an object from client to server and one of the
Trying to send a complex type between two systems that have the same code
I am trying to send emails from smtps (secure smtp) using Indy and the
I am trying to send data as a model from an html form to
I'm trying to send data from a client application using jQuery to a REST
I´m trying to send a image through tcp to a server, firts getting the
I'm trying to put a list of dictionary words from an AJAX call into
All, I'm trying to send the NSMutableDictionary response to another class of mine, or
Im trying to send an email to multiple addresses, so I wrote function that

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.