How to turn a C ++ / CLI.Net socket into boost :: asio socket?

What I want is just an example of code for creating a new asio socket buffer from a C ++ / CLI.Net socket. How to create such a thing?

Here is the pseudo code of what I would like to do:

.net::socket a;
boost::asio::socket b;
b.assign(a.nativeWin32Socket());
+3
source share
2 answers

You tried?

b.assign(a.Handle.ToInt32());

Also note that you will need to use the WSADuplicateSocket, as you can get both b and a to close the socket and not expect what you are not expecting.

So you need something like:

 SOCKET native = WSADuplicateSocket(a.Handle.ToInt32(),...);
 b.assign(native);

Full answer (tested)

SOCKET native = a->Handle.ToInt32();
// Now native is a real socket
b.assign(boost::asio::ip::tcp::v4(), native);

Now it’s nice to duplicate a socket using WSADuplicateSocket:

+4
source

assign, - asio. . Boost.Asio .

+2

All Articles