Sending data to a win32 socket hndle in .NET

K

kurt.kurtsmith

I have a COM object which returns the socket handle it is currently
connected to as a 32 bit WIN32 handle. I want to send data to this
already connected socket connection but can't seem to figure out what
call i need to make in order to send data using the Win32 handle. Is
this possible?
 
N

Nicholas Paldino [.NET/C# MVP]

If you want a "clean" way, there isn't, as there is no way to pass a
socket handle to a Socket instance and have it work off that.

If possible, what I would do is call the functions in the winsock
library through the P/Invoke layer to get the information about the socket
(type, address family, protocol type) and send the data on a new socket.

However, it seems like you aren't in a position to do that. There is a
private constructor for the Socket class which takes a SafeCloseSocket
instance (an internal class which derives from SafeHandle), all of which you
could access through reflection, but at that point, you are depending on
implementation details, and you could easily get bit by doing such a thing,
especially in this case (reflecting on private constructors that take
internal classes).
 
K

kurt.kurtsmith

If you want a "clean" way, there isn't, as there is no way to pass a
socket handle to a Socket instance and have it work off that.

If possible, what I would do is call the functions in the winsock
library through the P/Invoke layer to get the information about the socket
(type, address family, protocol type) and send the data on a new socket.

However, it seems like you aren't in a position to do that. There is a
private constructor for the Socket class which takes a SafeCloseSocket
instance (an internal class which derives from SafeHandle), all of which you
could access through reflection, but at that point, you are depending on
implementation details, and you could easily get bit by doing such a thing,
especially in this case (reflecting on private constructors that take
internal classes).

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I have a COM object which returns the socket handle it is currently
connected to as a 32 bit WIN32 handle. I want to send data to this
already connected socket connection but can't seem to figure out what
call i need to make in order to send data using the Win32 handle. Is
this possible?- Hide quoted text -

- Show quoted text -

Thanks Nicholas,

I went the P/Invoke route. Works for what I am trying to do.

I really appreciate your help.

Kurt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top