Convert System::Net::Sockets::Socket to winsock2's SOCKET?

Convert System::Net::Sockets::Socket to winsock2's SOCKET?

Post by U29uZ09mUn » Thu, 18 Oct 2007 01:09:02


Does anyone know how to do this?

Working on app that has new front end using old back end. New front end
uses System::Net::Sockets::Socket. Old back end uses winsock2's SOCKET.
Huge major extremely time-consuming PITA (and so not feasible) effort to
convert either of the ends.

Take care,
Melody
 
 
 

Convert System::Net::Sockets::Socket to winsock2's SOCKET?

Post by Alexander » Thu, 18 Oct 2007 04:03:01

But why? You can certainly use different frameworks for the
server and the client. It's the same ws2_32.dll underneath
anyway...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: XXXX@XXXXX.COM
MVP VC FAQ: http://www.yqcomputer.com/
=====================================

 
 
 

Convert System::Net::Sockets::Socket to winsock2's SOCKET?

Post by U29uZ09mUn » Thu, 25 Oct 2007 01:45:04

(I'm the OP - just logged into a different account)

When I say a different front end and back end, I don't mean server and
client. Rather the "back end" is the thread I spin off to serve a
just-connected client. So this is all the same application but the main
thread uses Net.Sockets and the client-support threads use winsock2.
 
 
 

Convert System::Net::Sockets::Socket to winsock2's SOCKET?

Post by U29uZ09mUn » Fri, 26 Oct 2007 19:23:00

I figured it out.

To "convert" from .NET sockets to old Winsock SOCKET...
System::Net::Sockets::Socket^ netSocket;
... // other code that opens netSocket...
SOCKET mySocket = (SOCKET)netSocket->Handle.ToPointer();

My troubles came about because I wasn't properly closing things. To do so...
shutdown(mySocket, SD_BOTH);
netSocket->Shutdown(SocketShutdown::Both);
netSocket->Close();

I needed to shutdown Both socket variables (or at least definitely the
netSocket one).