[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Client Server Application with Socket Programming for bandwidth computation

Posted on 2004-11-24
8
Medium Priority
?
688 Views
Last Modified: 2008-03-03
I'm totally new to java and I have to develop a client-server application where the server sends a stream of random bytes to the client during a time t. This time is divided into slices of the same lenght (for instance 20 ms). For each time slice I have to count the number of bytes received and divide it by the lenght of the time slice, obtaining a bandwidth sample. Then I have to use this value to calculate some statistics.

My question is if I need to use two threads, one that just receives data from the server and the other one that calculate the bandwidth samples and statistics, so I make sure that during each time slice I only receive data.

What do you think?

Thanks a lot!

I don't know a priori how many bandwidth samples I'm going to calculate. Data about each sample is used to calculate some statistics and then according to results I decide if I need a new sample or if I'm done. I have to calculate the minimum number of samples that gives me a certain confidence level.

Thanks.
0
Comment
Question by:Vijai
  • 4
  • 2
  • 2
8 Comments
 
LVL 2

Expert Comment

by:ThummalaRaghuveer
ID: 12670642
I guess you are correct, you have to use 2 threads. One thread listens to a socket and dumps data into a buffer. Other thread calculates the data in the buffer after every 20 ms(approximately) and calculates the bandwidth. I guess it would be easy if the second thread empties the buffer after calculating bandwidth for that sample. You need to synchronizze both the threads by obtaining a lock on buffer.

If you keep empting the buffer after every 20ms sample, It does not matter how many samples you are going to use.

-Raghu
0
 
LVL 3

Expert Comment

by:RuadRauFlessa
ID: 12672093
Well that would depend on the way in which you tend to reason. You can keep the data in a list/vector that can change it's size dinamically when you add data so the unknown amount of frames is not an issue. I would advise you against the multi threading if you are interested in calculating bandwidth statistics since when threading you will never be able to make full use of the bandwidth due to the threading model.

1. Get the start time
2. send the data
3. get the stop time
4. see if ihe diffirence is 20 ms (your frame length)
5. repeat stem 1..4 until the diffirence is 20ms
6. save the data in a structure for later processing
7. add the structure to a list
8. when everything stops then do the calculations as to not adversely affect the sending process.
0
 
LVL 2

Expert Comment

by:ThummalaRaghuveer
ID: 12672452
Its a description appropriate for server and not for client. If the same approach is used for client then as the number of sample bursts are not known then client might hang waiting for responses from server.

-Raghu
0
Technology Partners: 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!

 

Author Comment

by:Vijai
ID: 12688979
I don't know a priori how many bandwidth samples I'm going to get. Data about each sample is used to calculate some statistics and then according to results I decide if I need a new sample or if I'm done. I have to calculate the minimum number of samples that gives me a certain confidence level.

Thanks.
0
 
LVL 2

Expert Comment

by:ThummalaRaghuveer
ID: 12702093
May be you should just go with one thread that receives data... calculates bandwidth.. decides for further sampling... and continues....
0
 

Author Comment

by:Vijai
ID: 12708509
but the time is split in slices of 20 ms, and I have to count the amount of data I receive in that time to calculate bandwidth and other statistics. If I use part of the time in the slice to do that then my sequence of time slices doesn't cover my entire interval of time..
0
 
LVL 2

Expert Comment

by:ThummalaRaghuveer
ID: 12709382
If I understand correctly... you are usign a TCP stream and even if you calculate you do not lose any slices. Also you bandwidth is calculated at the client and not at the server. At the client side you know exactly how much time you are listeneing to and how much time you are calculating... So I guess that does not create any problems

-Raghu
0
 
LVL 3

Accepted Solution

by:
RuadRauFlessa earned 150 total points
ID: 12713368
Vijai if you are going to go with a multi thread solution you will lose even more time to threading controll than you will when you are only working with the main thread. This is due to synchronization, timing and such checks which the OS and the VM has to do in order to properly handle seperate threads. If you really wan't accurate figures I would urdge you to move away from Java since when you are working with timing of anything it is verry unpredictable and also uncontrolable.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 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