[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

UDP Socket Server Async New Client Instances?

Posted on 2011-02-17
4
Medium Priority
?
1,146 Views
Last Modified: 2012-05-11
I'm looking at this link concerning a UDP Socket Server Chat.
http://www.daveoncsharp.com/2009/08/csharp-chat-application-over-asynchronous-udp-sockets-part-1/

I question the accumulating client instances, could be hundreds in a very short time. I noticed an ArrayList used to hold client instances, but I think its purpose is for tracking and sending messages back to the clients. I don't think it's used for disposal purposes.

       Client client = new Client();

Q. What if the ArrayList is not used?

Q. Are the clients instances disposed automatically?
0
Comment
Question by:pointeman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 1600 total points
ID: 34919973
I really only made a cursory examination of the code in that link, but at a glance it looks like the ArrayList is used to keep track of logged in clients.  When an incoming message is received the server loops through the list and sends each client in the ArrayList a copy of the message.  When a client sends the "i'm logging out" message the appropriate Client is removed from the ArrayList.

The garbage collector will clean-up any unused objects automatically - such as Client's that have been removed from the list - but the garbage collector runs when it thinks it's necessary.  100's of these objects doesn't really seem like a big deal to me - the client object probably doesn't use much memory.

Although, if the client is using network resources it may be wise to implement IDisposable on the client class, and then call client.Dispose() after removing it from the ArrayList, this way the network resources are released immediately instead of waiting for the garbage collector to get around to it.
0
 
LVL 11

Assisted Solution

by:Sudhakar Pulivarthi
Sudhakar Pulivarthi earned 400 total points
ID: 34922518
Hi,

tgerbert was right with his analysis. Please check the data streams used in the code are getting closed immediately after use. Else they will be cleared only during finalization (resource waste).

Since broadcasting the message (Looping) to all clients will consume time in processing. So use unique ID for every login and perform all transaction to those specific client.
0
 

Author Comment

by:pointeman
ID: 34933666
So you both think the .NET garbage collection will take care of it?

If so, I won't worry about it anymore :)
0
 
LVL 33

Assisted Solution

by:Todd Gerbert
Todd Gerbert earned 1600 total points
ID: 34935153
Yes, "Client" is just a small struct, so there's really no need to clean'em up manually, the garbage collector will get'em - and even with thousands of them you should be fine on memory.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question