Solved

UDP Socket Server Async New Client Instances?

Posted on 2011-02-17
4
1,115 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
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 400 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 100 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 400 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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