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

  • Home
  • SEARCH
  • 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 870973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:34:01+00:00 2026-05-15T10:34:01+00:00

I’m attempting to send a .proto message from an iPhone application to a Java

  • 0

I’m attempting to send a .proto message from an iPhone application to a Java server via a socket connection. However so far I’m running into an issue when it comes to the server receiving the data; it only seems to process it after the client connection has been terminated. This points to me that the data is getting sent, but the server is keeping its inputstream open and waiting for more data. Would anyone know how I might go about solving this? The current code (or at least the relevant parts) is as follows:

iPhone:

Person *person = [[[[Person builder] setId:1] setName:@"Bob"] build];
RequestWrapper *request = [[[RequestWrapper builder] setPerson:person] build];
NSData *data = [request data];  
AsyncSocket *socket = [[AsyncSocket alloc] initWithDelegate:self];

if (![socket connectToHost:@"192.168.0.6" onPort:6666 error:nil]){
    [self updateLabel:@"Problem connecting to socket!"];
} else {
    [self updateLabel:@"Sending data to server..."];
    [socket writeData:data withTimeout:-1 tag:0];
    [self updateLabel:@"Data sent, disconnecting"];
    //[socket disconnect];
}

Java:

try {
        RequestWrapper wrapper = RequestWrapper.parseFrom(socket.getInputStream());
        Person person = wrapper.getPerson();
        if (person != null) {
            System.out.println("Persons name is " + person.getName());
            socket.close();
        }

On running this, it seems to hang on the line where the RequestWrapper is processing the inputStream. I did try replacing the socket writedata method with:

[request writeToOutputStream:[socket getCFWriteStream]];

(here I’m calling the gpb to write to the output stream, instead of writing the data generated to the output stream)

Which I thought might work, however I get an error claiming that the “Protocol message contained an invalid tag (zero)”. I’m fairly certain that it doesn’t contain an invalid tag as the message works when sending it via the writedata method.

Any help on the matter would be greatly appreciated!

Cheers!

Dan

(EDIT: I should mention, I am using the metasyntactic gpb code; and the cocoaasyncsocket implementation)

  • 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-15T10:34:02+00:00Added an answer on May 15, 2026 at 10:34 am

    Finally I managed to solve it!! It’s embarrassing how simple it was once I stopped caring about the GPB way of doing it. The C++ code I used is:

        NSData *data = [wrapper data]; 
        int s = [wrapper serializedSize]; 
        NSData *size = [NSData dataWithBytes:&s length:1]; 
        [sock writeData:size withTimeout:-1 tag:1]; 
        [sock writeData:data withTimeout:-1 tag:1]; 
    

    and then on the Java end I just kept the

        RequestWrapper.parseDelimitedFrom(socket.getInputStream())
    

    line and it works a treat! All I end up doing is sending the size of the data before the data itself and the GPB method on the Java end works out the rest!

    One major problem I had was actually converting the size of the data to send, from an int to NSData, and having it send across the network correctly. The way I was advised of doing it was
    NSData *size = [NSData dataWithBytes:&s length:sizeof(s)];

    However whenever I sent that across as data, it would seem to send the first byte, along with 3 “0” bytes. This caused havoc with GPB because if it receives a 0 byte at any point it throws an exception thinking the code is corrupt (my guess). Seeing as I never looked at the actual bytes coming across and analysing them until trying to do it a different way today, I am a bit gutted as I could have figured out that this was the issue a while ago. After some experimenting around with it, I gathered that the ‘sizeof’ method was the problem so I removed it. Currently I have just put a ‘1’ instead of the actual size, which
    seems to only return 1 byte when sending the data file across the network; although I’m not sure thats going to be an ‘ideal’ solution (although the message size should only be in 1 byte anyway) – if anyone could advise me why this sizeof() is causing an issue, it would be appreciated 🙂

    Points should really go to Luke Steffen who helped me with this on the cocoaasyncsocket google group despite my idiocy – so again, thanks Luke!

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

Sidebar

Ask A Question

Stats

  • Questions 501k
  • Answers 501k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer here is a good tutorial that can help u UPDATE… May 16, 2026 at 2:26 pm
  • Editorial Team
    Editorial Team added an answer To indicate to Ruby on Rails that the users table… May 16, 2026 at 2:26 pm
  • Editorial Team
    Editorial Team added an answer change <a onclick="addItemToUsersList("<?php echo $itemid ; ?>")"> into <a onclick="addItemToUsersList(<?php… May 16, 2026 at 2:26 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

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.