473,382 Members | 1,814 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,382 software developers and data experts.

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.Sockets.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(IntPtr hSocket,IntPtr
lpOverlapped,UInt32 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.Sockets.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.Disconnect()
method.

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

Thanks,

Greg

Nov 17 '05 #1
0 4048

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

Similar topics

0
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...
0
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...
10
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)...
3
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...
7
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...
1
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...
2
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...
4
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...
0
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. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.