• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Interrupting Events

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing an application that provides reliable network transport over a deliberately unreliable socket (it is a university assignment). At this stage it is just a stop-and-wait protocol. I want to have two events that can trigger a resend:

* timeout event
* incorrectly numbered ack received

My question is, how do I start a timer and have either Unreliabe.receive() or a timeout event trigger a resend? Two events that cause one action.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

nc.util.Timer sounds appropriate for the timeout.

I suggest you start a "timeout thread" as soon as you start waiting (after you sent a packet, I guess), something like this:




Then, you start waiting for the ACK. When it arrives, just set canceled to true and the thread you started will quietly do nothing when it will run().

Note: (make sure you have exactly one canceled variable per Thread you start and not a unique global one => maybe encapsulating it in the TimerTask or something)
 
Tristan McHardie
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, thanks for the help!

My next problem should probably be in the begginner forum, but I'll keep it in this thread as it's directly related to it.

The send() method below is an overriding method, which adds TCP-like reliability to a UDP socket. After the headers have been added, I need to call super.send() to pass the reliable packet to the unreliable socket.

My question is, how do I call super.send() from within the TimerTask, which is obviously a subclass?

Thanks,
Tristan

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe "OuterClassName.super.send()" will work.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic