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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:35:10+00:00 2026-05-29T22:35:10+00:00

I am trying to write a small application to process networking packet. To facilitate

  • 0

I am trying to write a small application to process networking packet. To facilitate the test, I hope this app can operate in two mode: local streaming mode (using std::cin) and network streaming mode (using asio) – based on if the command line provides a port number for example. The goal is make it transparent to rest of the client class(es) who do the actual parsing of the packet, for example, they can grab a reference to the stream, event_stream, then do parsing as:

event_stream >> MsgHeader;

Assuming the class MsgHeader has a overload operator >>.

For local stream mode: I am just return &cin. For networking mode, I hope I can do something like this:

boost::asio::io_service io_s;
tcp::acceptor acc(io_s. tcp::endpoint(tcp::v4(), 1950));
tcp::iostream stream;
acc.accept(*stream.rdbuf()); // act as server, another client will write to it.
return &stream;

But I am a little lost how to make the rest of the client “unaware” of what kind stream they are deal with? Can I just declare it such as:

std::istream &in = get_event_stream();
  • 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-29T22:35:11+00:00Added an answer on May 29, 2026 at 10:35 pm

    Two possibilities:

    1. Templatize everything on the stream type. Might be overkill, but allows flexibility for streams that don’t all adhere to a standard interface (through specialization). Different interfaces will need different specializations, but the high-level interface (the calling of the template) will be uniform at least.

    2. Make sure all streams you use inherit from the same base class (if not, provide adaptor classes to wrap around the difference in interface), and use that. I’m not sure if a reference will work here, you might need a pointer variable instead, like this:

      std::istream *in = &get_event_stream();

    Then make your functions take a pointer to the base class (here std::istream), and only use functions the base class has:

    void some_function( std::istream *in );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a small test application that uses the UMLS UTS
I'm trying to write a small application that needs to use the clipboard for
I am trying to write a small application using bouncycastle algorithm, from the BouncyCastleProvider.java
I've been trying to write a small application which will work with mysql in
I'm trying to write a small wsgi application which will put some objects to
I'm creating a small vb.net application, and I'm trying trying to write a list
I'm trying to write a small app that monitors how much power is left
I am trying to write a small application to learn about developing for Facebook
I am trying to write a small Cocoa application that helps me manage my
I am trying to write a small php application and i am facing a

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.