Results 1 to 2 of 2
  1. #1
    saru88 is offline Member
    Join Date
    Oct 2008
    Rep Power

    Default Datagram Client and Server, client timer question

    i'm very new to networking in Java and I'm trying to implement
    a datagram client and server. My problem atm is writing a timer for the
    client in java so that if the server does not respond within a certain time period then the client's request is resent. Could someone please show me how i would do this :), i have looked at the Timer class but my experimentation with it failed.

    This was my experiment, out of curiousity could u tell me why "hello" was
    not printed out.

    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Timer;
    public class Timers {
    	public static void main(String[] args){
    		int delay = 1000; //milliseconds
    		  ActionListener taskPerformer = new ActionListener() {		     
    			public void actionPerformed(ActionEvent arg0) {
    		  new Timer(delay, taskPerformer).start();
    Thanx :)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    It probably is the type of thread that Timer uses. If the main thread exits, the jvm exits and the timer is lost.
    Read about daemon threads.
    Add a try{Thread.sleep(2000);}catch(Exception x){} // wait
    before main exits to see.

Similar Threads

  1. Server not able to connect client
    By Kapil Gupta in forum New To Java
    Replies: 15
    Last Post: 07-22-2008, 04:09 AM
  2. how client know what kind of server
    By lemur in forum Networking
    Replies: 3
    Last Post: 05-31-2008, 07:11 AM
  3. client/server palindrom
    By Rgfirefly24 in forum New To Java
    Replies: 0
    Last Post: 04-28-2008, 02:19 AM
  4. Identify Client in Socket Client Server Application
    By masadjie in forum Networking
    Replies: 1
    Last Post: 12-20-2007, 09:18 AM
  5. Problems with client and server
    By Albert in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 06:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts