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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:19:37+00:00 2026-05-23T07:19:37+00:00

My problem is that when I do TcpClient con = new TcpClient (127.0.0.1, 5432);

  • 0

My problem is that when I do

TcpClient con = new TcpClient ("127.0.0.1", 5432);
            NetworkStream str = con.GetStream ();
Annoucement msg = new Annoucement ();
            msg.typ = Annoucement.msgType.NOWY_GRACZ;

            Serializer.SerializeWithLengthPrefix (str, msg, PrefixStyle.Base128);
            Serializer.SerializeWithLengthPrefix (str, msg, PrefixStyle.Base128);

and I try to receive with custom library that uses protocol buffers

Connection con = server.accept();

    Annoucement ann = con.receive();
    cout << ann.typ() << endl;

    ann = con.receive();
    cout << ann.typ() << endl;

I can read only the first one. The second is wrong because the field typ is set to 0 whereas it should be 3. I think that function receive do something wrong but don’t know what.

  Annoucement Connection::receive() throw(EmptySocket) {
    CodedInputStream coded_input(raw_input);
    google::protobuf::uint32 n;
    coded_input.ReadVarint32(&n);
    char *b;
    int m;
    coded_input.GetDirectBufferPointer((const void**)&b, &m);
    Annoucement ann;
    ann.ParseFromArray(b, n);
    return ann;
  }

one variable is initialised in constructor

FileInputStream* raw_input;
 raw_input = new FileInputStream(s);  //s is socket in this example communication

How can I modify it so that I can read consecutive messages from the socket?

  • 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-23T07:19:38+00:00Added an answer on May 23, 2026 at 7:19 am

    From the reference:

    Sets *data to point directly at the
    unread part of the CodedInputStream’s
    underlying buffer, and *size to the
    size of that buffer, but does not
    advance the stream’s current position.

    This will always either produce a
    non-empty buffer or return false. If
    the caller consumes any of this data,
    it should then call Skip() to skip
    over the consumed bytes. This may be
    useful for implementing external fast
    parsing routines for types of data not
    covered by the CodedInputStream
    interface.

    I see these missing in your code:

    1. Handling the case where both the announcements are already in the buffer on the first call.
    2. Calling coded_input.Skip() (should cover #1 above if used right)
    3. Error handling (including the case where there are no announcements already in the buffer at the call).

    I’m guessing your problem is caused by #3 above, but I’m not sure until I see the ParseFromArray code.

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

Sidebar

Related Questions

I'm using TcpListener to accept & read from TcpClient . The problem is that
One problem that I come across regularly and yet don't have a solution to
A problem that we need to solve regularly at my workplace is how to
The problem that I am having has to do with the need to keep
A problem that has frequently come up in my career is I have some
Simple problem that I can't figure out... How can I print a '%' character
I have a problem that confuses my users, being that although an item is
This has been a problem that I haven't been able to figure out for
I have the problem that an specific step in Ant can only be executed
I am having the problem that I cannot select a specific XML node which

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.