473,499 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket Collection

I have a socket-based app running that spawns a different socket for each
user and I was looking for a way to optimize it a little better.

Currently I keep a collection of active sockets (300 - 400). My plan was to
capture the Socket IntPtr Handle when they connect and then each time I
needed to send information to that particular socket, I would call the
private Socket constructor via Reflection and use the IntPtr value as the
handle parameter. I would be maintaining a collection of 32 bit values
rather than a collection of Sockets.

My question is... do I gain anything by doing this? (1) Is reflection fast
enough in this instance. (2) Do I really get any type of performance gain
by storing the handle and not the object?

Thanks.
Nov 16 '05 #1
3 1727
Nevermind... this way loses the reference to the socket, so it is not a
good alternative.

"Paul W" <an*******@yahoo.com> wrote in message
news:Ykqzc.11501$wS2.4327@okepread03...
I have a socket-based app running that spawns a different socket for each
user and I was looking for a way to optimize it a little better.

Currently I keep a collection of active sockets (300 - 400). My plan was to capture the Socket IntPtr Handle when they connect and then each time I
needed to send information to that particular socket, I would call the
private Socket constructor via Reflection and use the IntPtr value as the
handle parameter. I would be maintaining a collection of 32 bit values
rather than a collection of Sockets.

My question is... do I gain anything by doing this? (1) Is reflection fast enough in this instance. (2) Do I really get any type of performance gain
by storing the handle and not the object?

Thanks.

Nov 16 '05 #2
I would not think so. Just keep an arraylist or other collection of
sockets. You want the socket objects to live for life of connection.

--
William Stacey, MVP

"Paul W" <an*******@yahoo.com> wrote in message
news:f_vzc.11594$wS2.10639@okepread03...
Nevermind... this way loses the reference to the socket, so it is not a
good alternative.

"Paul W" <an*******@yahoo.com> wrote in message
news:Ykqzc.11501$wS2.4327@okepread03...
I have a socket-based app running that spawns a different socket for each user and I was looking for a way to optimize it a little better.

Currently I keep a collection of active sockets (300 - 400). My plan was

to
capture the Socket IntPtr Handle when they connect and then each time I
needed to send information to that particular socket, I would call the
private Socket constructor via Reflection and use the IntPtr value as the handle parameter. I would be maintaining a collection of 32 bit values
rather than a collection of Sockets.

My question is... do I gain anything by doing this? (1) Is reflection

fast
enough in this instance. (2) Do I really get any type of performance gain by storing the handle and not the object?

Thanks.



Nov 16 '05 #3
I am not sure you gain anything here. For starters, if I am getting this
correctly, you want to do the following:

Socket client = serversocket.Accept();
myhandlelist.Add(client.Handle);

and then you will use the IntPtr from then on.

First notice, that you are storing the native handle. That means the OS
resources backing the socket have already been allocated. So, the most you
are saving is managed memory on the GC.

You might want to rethink the architecture of your application to make sure
you are using resources efficiently. For example, if your connections are
longlived (session oriented) then you might want to keep the connections
around for a certain amount of time. This involves coming up with a
connection management algorithm, whereby you time out and close idle
connections etc. However you will have to weigh the potential gain in
performance with respexct to the efffort involved in
designing/implementing/debugging such a scheme.

--

Thanks

feroze
=============
This posting is offered as-is. It offers no warranties and confers no
rights.

"Paul W" <an*******@yahoo.com> wrote in message
news:f_vzc.11594$wS2.10639@okepread03...
Nevermind... this way loses the reference to the socket, so it is not a
good alternative.

"Paul W" <an*******@yahoo.com> wrote in message
news:Ykqzc.11501$wS2.4327@okepread03...
I have a socket-based app running that spawns a different socket for each user and I was looking for a way to optimize it a little better.

Currently I keep a collection of active sockets (300 - 400). My plan was

to
capture the Socket IntPtr Handle when they connect and then each time I
needed to send information to that particular socket, I would call the
private Socket constructor via Reflection and use the IntPtr value as the handle parameter. I would be maintaining a collection of 32 bit values
rather than a collection of Sockets.

My question is... do I gain anything by doing this? (1) Is reflection

fast
enough in this instance. (2) Do I really get any type of performance gain by storing the handle and not the object?

Thanks.


Nov 16 '05 #4

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

Similar topics

5
3668
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
1
3375
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows...
1
372
by: piotrek | last post by:
Hello all. I have a problem and my solution but i have to make sure that it want cause memory problems. i have a class FTP and 'private Socket CONNECTION = null;' Then i have a method PASV()...
2
7531
by: Ben | last post by:
I need to send data from a client to a server. In the server code I have: s = ServerSocket.Accept() If (s.Connected = False) Then MsgBox("Unable to connect", , "Server Error") Exit Sub End...
0
7220
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...
1
6894
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...
0
7388
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...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
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...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
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...

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.