I am implementing 2 applications that use the sliding window protocol as a data link protocol and UDP Sockets to communicate. I am trying to implement the sliding window protocol using the Tanembaum's book as reference. Here's the code I found in the book.
I am a little confused in translating this to java. I don't know exactly how threads are applied here. I am looking for any hints and strategies that will help me implementing this.
EDIT
I'm most confused :
- in implementing the functions wait_for_event() and start_timer().
- Where should I put the UDP sockets part? I think the UDP socket part is within to_physical_layer() and from_physical_layer(). Correct if I'm wrong.
- Should both application have the same code since the protocol is bidirectional?
closed as not a real question by user177800, Jim Garrison, Aleksander Blomskøld, Gajotres, RidcullyFeb 3 '13 at 10:15
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.
2 Answers
Next bond film after spectre. in implementing the functions wait_for_event() and start_timer().
You don't need them. Use DatagramSocket.setSoTimeout()
and catch (SocketTimeoutException)
respectively.
Where should I put the UDP sockets part? I think the UDP socket part is within to_physical_layer() and from_physical_layer(). Correct if I'm wrong.
Same place as the present recv()
and send()
calls.
Sliding Window Protocol Java Program Download
Should both application have the same code since the protocol is bidirectional?
• Install the parts or files downloaded on your PC. • When Crack has been downloaded, just disconnect your internet connection. • Copy the crack and paste it into the installation process directory where you have Solidworks 2017 installed.
Yes.
Welcome 2018| Bollywood Remix Songs Back To Back. Lets set the dance floor, set the dance mood. Hindi remix songs 2018.
First of all: before investing time and effort into a sliding-window layer on top of UDP, check whether you need such an exotic solution. TCP already does that kind of stuff, and many people have invested lots of time in getting it right and robust. But there are of course valid reasons to implement such a solution. The next step should be to google around, chances are there are already dozens of very similar programs around. Especially because you don't seem to have a lot of experience with Java's networking API's it's probably a whole lot more efficient to start from a working piece of Java code than from an example from a book that's more geared toward learning people networking concepts.
Anyways, if you want to reimplement the protocol above start by reading the Javadoc for the DatagramSocket class. It has a setSoTimeout method that can replace the timer thing in the code above, the main difference being that upon timeout receive will throw a SocketTimeoutException, and that may complicate your program's flow a little. Forget the from_physical and to_physical bits, all that stuff is wrapped by the Socket classes.
Not the answer you're looking for? Browse other questions tagged javanetworkingudpprotocolssliding-window or ask your own question.
PermalinkJoin GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign up1 contributor
packagestorm.starter.tools; |
importjava.io.Serializable; |
importjava.util.Map; |
/** |
* This class counts objects in a sliding window fashion. |
* <p/> |
* It is designed 1) to give multiple 'producer' threads write access to the counter, i.e. being able to increment |
* counts of objects, and 2) to give a single 'consumer' thread (e.g. {@link PeriodicSlidingWindowCounter}) read access |
* to the counter. Whenever the consumer thread performs a read operation, this class will advance the head slot of the |
* sliding window counter. This means that the consumer thread indirectly controls where writes of the producer threads |
* will go to. Also, by itself this class will not advance the head slot. |
* <p/> |
* A note for analyzing data based on a sliding window count: During the initial <code>windowLengthInSlots</code> |
* iterations, this sliding window counter will always return object counts that are equal or greater than in the |
* previous iteration. This is the effect of the counter 'loading up' at the very start of its existence. Conceptually, |
* this is the desired behavior. |
* <p/> |
* To give an example, using a counter with 5 slots which for the sake of this example represent 1 minute of time each: |
* <p/> |
* <pre> |
* {@code |
* Sliding window counts of an object X over time |
* |
* Minute (timeline): |
* 1 2 3 4 5 6 7 8 |
* |
* Observed counts per minute: |
* 1 1 1 1 0 0 0 0 |
* |
* Counts returned by counter: |
* 1 2 3 4 4 3 2 1 |
* } |
* </pre> |
* <p/> |
* As you can see in this example, for the first <code>windowLengthInSlots</code> (here: the first five minutes) the |
* counter will always return counts equal or greater than in the previous iteration (1, 2, 3, 4, 4). This initial load |
* effect needs to be accounted for whenever you want to perform analyses such as trending topics; otherwise your |
* analysis algorithm might falsely identify the object to be trending as the counter seems to observe continuously |
* increasing counts. Also, note that during the initial load phase <em>every object</em> will exhibit increasing |
* counts. |
* <p/> |
* On a high-level, the counter exhibits the following behavior: If you asked the example counter after two minutes, |
* 'how often did you count the object during the past five minutes?', then it should reply 'I have counted it 2 times |
* in the past five minutes', implying that it can only account for the last two of those five minutes because the |
* counter was not running before that time. |
* |
* @param <T> The type of those objects we want to count. |
*/ |
publicfinalclassSlidingWindowCounter<T> implementsSerializable { |
privatestaticfinallong serialVersionUID =-2645063988768785810L; |
privateSlotBasedCounter<T> objCounter; |
privateint headSlot; |
privateint tailSlot; |
privateint windowLengthInSlots; |
publicSlidingWindowCounter(intwindowLengthInSlots) { |
if (windowLengthInSlots <2) { |
thrownewIllegalArgumentException( |
'Window length in slots must be at least two (you requested '+ windowLengthInSlots +')'); |
} |
this.windowLengthInSlots = windowLengthInSlots; |
this.objCounter =newSlotBasedCounter<T>(this.windowLengthInSlots); |
this.headSlot =0; |
this.tailSlot = slotAfter(headSlot); |
} |
publicvoidincrementCount(Tobj) { |
objCounter.incrementCount(obj, headSlot); |
} |
/** |
* Return the current (total) counts of all tracked objects, then advance the window. |
* <p/> |
* Whenever this method is called, we consider the counts of the current sliding window to be available to and |
* successfully processed 'upstream' (i.e. by the caller). Knowing this we will start counting any subsequent |
* objects within the next 'chunk' of the sliding window. |
* |
* @return The current (total) counts of all tracked objects. |
*/ |
publicMap<T, Long>getCountsThenAdvanceWindow() { |
Map<T, Long> counts = objCounter.getCounts(); |
objCounter.wipeZeros(); |
objCounter.wipeSlot(tailSlot); |
advanceHead(); |
return counts; |
} |
privatevoidadvanceHead() { |
headSlot = tailSlot; |
tailSlot = slotAfter(tailSlot); |
} |
privateintslotAfter(intslot) { |
return (slot +1) % windowLengthInSlots; |
} |
} |
Copy lines Copy permalink