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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:12:25+00:00 2026-05-30T13:12:25+00:00

Developing a network application, I have a Connection class that manages sending and receiving

  • 0

Developing a network application, I have a Connection class that manages sending and receiving messages on the network. I’m using boost::asio.

I now want to let the Connection class handle connections both over TCP, and over local UNIX stream sockets. However, the template-design of boost confuses me. AFAICT, there’s no shared base-class between local::stream_protocol::socket and ip::tcp::socket.

How would I go about creating a Connection that encapsulates the network-semantics such that other code don’t have to deal with the details of what protocol is used?

I.E. I want to implemented something like:

class Connection() {
  Connection(ip::tcp::endpoint& ep);
  Connection(local::stream_protocol::endpoint& ep);

  void send(Buffer& buf);
}

How would I achieve this?

  • 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-30T13:12:27+00:00Added an answer on May 30, 2026 at 1:12 pm

    After some pondering, my current solution is to make the send and recv functions of Connection virtual, and create a template-subclass of Connection, roughly:

    template <typename Protocol>
    class ConnectionImpl : public Connection {
        typedef typename Protocol::socket Socket;
        typedef typename Protocol::endpoint EndPoint;
    
        Socket _socket;
    public:
        ConnectionImpl(boost::asio::io_service& ioSvc, const EndPoint& addr) 
            : Connection(ioSvc), _socket(ioSvc) { 
            _socket.connect(addr);
        }
    
        void trySend() {
            // Initiate async send on _socket here
        }
    
        void tryRead() {
            // Initiate async recv on _socket here
        }
    }
    

    Is there a way to avoid the need to subclass and use of virtual functions?

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

Sidebar

Related Questions

I'm developing an application that manages network interfaces on behalf of the user and
I am developing a network application on iPhone that requires internet connection all the
I'm currently developing an application that will be run on local network in B2B
I am developing an application simulating a network comprising a number of nodes that
I have an ASP.NET MVC application that I'm working on. I've been developing it
i have been working on developing an blackberry application. as per now i want
I'm developing an ASP MVC3 application and I have some views that are related
Hello I am developing an application that will exchange unique groups and messages belonging
I'm thinking about developing an application for offline Handwriting Recognition using neural network. I
I am currently involved in developing a low level network application. We have lately

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.