?
Solved

UDP Socket Server Async New Client Instances?

Posted on 2011-02-17
4
Medium Priority
?
1,143 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 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