473,699 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket Reuse With .NET Framework 1.1 and C#

I apologize in advance if I am posting to the wrong group, but at least
one of my questions is related to Platform Invoke in C#.

I am using .NET Framework 1.1, and for improved performance, I need to
be able to reuse a client socket by placing it into a pool.
Unfortunately, with .NET Framework 1.1 I have no way to close a
socket's connection to a remote host without disposing of the socket's
resources altogether (i.e, Socket.Close()) , which prevents reuse of the
socket.

It appears that the .NET Framework 2.0 provides a Disconnect() method
that allows the socket handle to be reused, but I am restricted to
using .NET Framework 1.1 at this time.

My strategy right now is to extend the System.Net.Sock ets.Socket class
to include a Disconnect() method that calls the Winsock2 API's
DisconnectEx() function, but there are two problems that I am unable to
overcome:

1. I cannot get the .NET Framework to locate an entry point for the
DisconnectEx() function. The following code returns an exception that
states that an entry point cannot be found for the DisconnectEx()
function:

[DllImport("ws2_ 32.dll")]
private static extern Boolean DisconnectEx(In tPtr hSocket,IntPtr
lpOverlapped,UI nt32 dwFlags, UInt32 reserved);

When I try to call this declared function, the exception is thrown. Am
I referencing the correct dll?

2. I am uncertain as to whether or not I will have to wrap the Winsock2
API's ConnectEx() function in order to reuse the handle. The API
documentation states that the handle can be passed to the ConnectEx()
and AcceptEx() functions when the DisconnectEx() function is called
with the dwFlags argument set to TF_REUSE_SOCKET . Which, to me,
implies that I may also have to wrap the TransmitFile() API function in
my class.

It seems silly to me that I might have to essentially rewrite the
System.Net.Sock ets.Socket class in order to get a disconnect method
that allows me to reuse my socket. I simply want the same functionality
as that provided by the .NET Framework 2.0's Socket.Disconne ct()
method.

Can anyone make a suggestion that might get me on my way?

Thanks,

Greg

Nov 17 '05 #1
0 4064

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

Similar topics

0
1798
by: Helge Nilsen | last post by:
Hi, I have challange related to JMS usage of sockets. A JMS Client connect to a JMS Server over HTTPS through a proxy. My understanding is that a socket is created between the JMS client and proxy and another socket is created between the proxy and the remote JMS Server for single JMS message. Is this correct? The problem is that a huge number of JMS messages is supposed to be
0
2351
by: anuradha.k.r | last post by:
hi, I 'v e written both the server and client side socket programs in perl( a very small one).My socket is created and shows that the connection is established with the client.however I am not able to receive data in server side.I think the client sends the data properly.Somehow receive does not happen. Can someone tell me what could be wrong? My code is part of the sample programs available for socket prgmng in the net. Here is the...
10
5301
by: feel52 | last post by:
Below you'll find the code i'm working on. It's in a button click routine and hangs after 3 or 4 sometimes 5 loops done, probably in sock.receive(....). Some code was found here( on google i mean) but the amazing( at least for me) is that if i run the program step by step or i cancel the loop and run it by pressing the button again and again it never hangs . I want to have an infinite loop so my socket keeps on listening until i...
3
2539
by: Jimbo | last post by:
Hi Guys, I'm sorry if you have heard this one before but searching the net hasn't found a solution. I am using Socket in a client to connect to a server. However, after I've finished sending and recieving data and call the Close() method the socket lingers for a couple of minutes. This is demonstrated by using netstat -a. I've tried an assortment of SocketOptions (Linger, and DontLinger), but
7
2931
by: | last post by:
Hi all, I have a simple .aspx page running on net 2.0 that is trying to do a http post to a remote server. Here is the code Private Function ProcessRequests(ByVal strbody As String) As String Dim returnstr As String Dim URL As String = "http://www.dydomain.com/test.asp"
1
9432
by: Bob | last post by:
I am trying to reuse a socket address but I am having problems. What I am doing is creating a socket, connecting, then getting the LocalEnd point. I then Disconnect and try to connect again using the same address but I get an error 10048 . Can someone tell me what I am doing wrong. Here is the code... ws_socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); //Set the reuse address flag....
2
15324
by: djc | last post by:
I read a network programming book (based on framework 1.1) which indicated that you should 'never' use the RecieveTimeout or the SendTimeout 'socket options' on TCP sockets or you may loose data. I now see the socket.RecieveTimeout 'property' in the visual studio 2005 help documentation (framework 2.0) and it has example of it being used with TCP socket. This propery is also listed as 'new in .net 2.0'. 1) is the socket.RecieveTimeout...
4
1918
by: carl_bevil | last post by:
I would like to use a single port to connect to a server. I would like to be able to disconnect a socket using this port and then be able to connect again (on the same port) immediately. I know there is a TIME_WAIT value, but I thought I could get around it by using the ResuseAddress option. Here is what the code looks like (C#): Socket connectSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
0
1827
by: mhetfield | last post by:
Hi, I'm writing a client-server socket program. the client will be an instance of the well-known telnet application. i want to implement a simple authentication between the server and the client. - the client should send this message (after the connection established): my password "anypassword" and the server will check, if it's not the same password that's hardcoded in the server program, the server close connection. so the client will...
0
8615
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9173
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9033
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8911
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6533
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.