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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:40:07+00:00 2026-06-01T02:40:07+00:00

The title is my question. I already found a topic related to this here

  • 0

The title is my question.

I already found a topic related to this here -> Using SSL sockets and non-SSL sockets simultaneously in Boost.Asio?
and basically I’m in the same situation but for some reason I couldn’t comment there and/or contact the questioner directly so I’m doing this as a new question.

I have a set up ssl socket ssl::stream<ip::tcp::socket> socket_; where clients can connect just fine with

socket_.async_handshake(ssl::stream_base::server, session::handle_handshake)

and then read/write with

async_write(socket_, buffer(send_data, send_length), session::handle_read)
socket_.async_read_some(buffer(recieved_data, max_length), session::handle_read)

However now I want to use the same type of socket to build up connections that dont use SSL.

First of all I’m unsure how to do the “handshaking” as it is done with a SSL connection as I mentioned above.
By looking at some normal boost.asio example I assume that I dont have to do that for non-ssl connections and just directly read/write to the socket once it has been accepted?

Then as a next step I tried to do it as decsribed in the topic I mentioned above, I added a boolean ssl to session to check whether its a SSL connection or not.
Then instead of using socket_ in the async functions, I used socket_.lowest_layer().

Here’s the suggested code:

if ( sslEnabled )
    boost::asio::async_write( secureSocket_ );
} else {
    boost::asio::async_write( secureSocket_.lowest_layer() );
}

However it seems that the compiler doesnt accept this solution. When I try to compile the code with an async function that has socket_.lowest_layer() as a stream this error shows up (its only for async_read, async_write has a similar one):

boost\asio\impl\read.hpp(263): error C2039: 'async_read_some' : is not a member of 'boost::asio::basic_socket<Protocol,SocketService>'
          with
          [
              Protocol=boost::asio::ip::tcp,
              SocketService=boost::asio::stream_socket_service<boost::asio::ip::tcp>
          ]
          boost\asio\impl\read.hpp(255) : while compiling class template member function 'void boost::asio::detail::read_op<AsyncReadStream,MutableBufferSequence,CompletionCondition,ReadHandler>::operator ()(const boost::system::error_code &,size_t,int)'
          with
          [
            AsyncReadStream=boost::asio::basic_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>>,
              MutableBufferSequence=boost::asio::mutable_buffers_1,
              CompletionCondition=boost::asio::detail::transfer_all_t,
              ReadHandler=boost::_bi::bind_t<void,boost::_mfi::mf2<void,CSocket,const boost::system::error_code &,size_t>,boost::_bi::list3<boost::_bi::value<CSocket *>,boost::arg<1>,boost::arg<2>>>
          ]
          boost\asio\impl\read.hpp(527) : see reference to class template instantiation 'boost::asio::detail::read_op<AsyncReadStream,MutableBufferSequence,CompletionCondition,ReadHandler>' being compiled
          with
          [
              AsyncReadStream=boost::asio::basic_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>>,
              MutableBufferSequence=boost::asio::mutable_buffers_1,
              CompletionCondition=boost::asio::detail::transfer_all_t,
              ReadHandler=boost::_bi::bind_t<void,boost::_mfi::mf2<void,CSocket,const boost::system::error_code &,size_t>,boost::_bi::list3<boost::_bi::value<CSocket *>,boost::arg<1>,boost::arg<2>>>
          ]
          c:\asio_test\source\server.cpp(131) : see reference to function template instantiation 'void boost::asio::async_read<boost::asio::basic_socket<Protocol,SocketService>,boost::asio::mutable_buffers_1,boost::_bi::bind_t<R,F,L>>(AsyncReadStream &,const MutableBufferSequence &,const ReadHandler &)' being compiled
          with
          [
              Protocol=boost::asio::ip::tcp,
              SocketService=boost::asio::stream_socket_service<boost::asio::ip::tcp>,
              R=void,
              F=boost::_mfi::mf2<void,CSocket,const boost::system::error_code &,size_t>,
              L=boost::_bi::list3<boost::_bi::value<CSocket *>,boost::arg<1>,boost::arg<2>>,
              AsyncReadStream=boost::asio::basic_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp>>,
              MutableBufferSequence=boost::asio::mutable_buffers_1,
              ReadHandler=boost::_bi::bind_t<void,boost::_mfi::mf2<void,CSocket,const boost::system::error_code &,size_t>,boost::_bi::list3<boost::_bi::value<CSocket *>,boost::arg<1>,boost::arg<2>>>
          ]

Build FAILED.

So now I’m pretty much stuck and I really hope you can help me. Searching for the error brought up nothing and since it should supposedly work I dont know what the mistake could be…

  • 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-06-01T02:40:08+00:00Added an answer on June 1, 2026 at 2:40 am

    Actually I think I solved it now.

    1) The “handshaking” on a non-ssl is indeed not necessary, I immediately do async_reading after the accept

    2) Instead of async_read/write( socket_.lowest_layer(), ... ) I had to use socket_.next_layer().async_read_some( buffer, handler) and
    async_write( socket_.next_layer(), ... )

    I still dont know why it doesnt work with socket_.lowest_layer() (if someone knows, please explain) but at least it works just fine with the above methods. And I hope this will help other people with a similar problem too 😉

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

Sidebar

Related Questions

This question is a bit of a two-parter. First, the title question. Here's what
I already found this existing question Is this possible in XHTML: tags in a
I believe the title already says it all, but here is my question: what
Yes this question as already been asked here at SO. The problem is that
Question is already been asked in title. Here is a code: (function($){ var filter
I have tried looking though several of the already asked question about this topic
I'm sure this question has already been asked, but I can't found the good
the title already tells the question: you can successfully call the Print-Method on a
OK the question title is vague, but here's the problem. I have a list
I couldn't find this question already being asked on this forum. I am little

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.