Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-05-2008, 09:59 AM
Member
 
Join Date: Oct 2008
Posts: 1
Rep Power: 0
saru88 is on a distinguished road
Default Datagram Client and Server, client timer question
hey,
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.

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() {		     

			@Override
			public void actionPerformed(ActionEvent arg0) {
				System.out.println("hello");
				
			}
		  };
		  new Timer(delay, taskPerformer).start();
	}
}
Thanx
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-05-2008, 04:12 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Server not able to connect client Kapil Gupta New To Java 15 07-22-2008 05:09 AM
how client know what kind of server lemur Networking 3 05-31-2008 08:11 AM
client/server palindrom Rgfirefly24 New To Java 0 04-28-2008 03:19 AM
Identify Client in Socket Client Server Application masadjie Networking 1 12-20-2007 10:18 AM
Problems with client and server Albert Advanced Java 2 07-02-2007 07:07 AM


All times are GMT +2. The time now is 07:46 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org