473,387 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Sending data to a win32 socket hndle in .NET

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?

Jun 1 '07 #1
2 2492
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]
- mv*@spam.guard.caspershouse.com

<ku************@gmail.comwrote in message
news:11*********************@i38g2000prf.googlegro ups.com...
>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?

Jun 1 '07 #2
On Jun 1, 1:21 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com

<kurt.kurtsm...@gmail.comwrote in message

news:11*********************@i38g2000prf.googlegro ups.com...
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
Jun 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tim Black | last post by:
My application requires sending a large piece (~2MB) of data to several devices on a network via TCP sockets. I have experimented with different methods for doing this and this has raised some...
1
by: Daniel | last post by:
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" what am i doing wrong? is there some thing else i need to do to free up the socket...
3
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data...
4
by: Winston Nimchan | last post by:
Hi: I'm currently developing a socket application and would like to precede the data being sent with a 4 byte message length header (bin4). Can anyone help Regards Winston
4
by: yaron | last post by:
Hi, I have a problem when sending data over TCP socket from c# client to java server. the connection established ok, but i can't send data from c# client to java server. it's work ok with...
3
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
5
by: Jens | last post by:
Hello, I have been looking for some C-code which listens on a user-defined port for incoming data traffic. When data is received, the data is written to a file. I found some C-code (server)...
10
by: Markgoldin | last post by:
I am sending an XML data from not dontnet process to a .Net via socket listener. Here is a data sample: <VFPData> <serverdata> <coderun>updateFloor</coderun> <area>MD2</area>...
2
by: =?Utf-8?B?R3JlZ0lJ?= | last post by:
Hi All, I have some problems with sending UDP packets using Winsock. I tried to send some to a closed port, and according to the documentation on Microsoft MSDN site...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.