View Single Post
  #1 (permalink)  
Old 01-10-2008, 11:40 AM
dim_ath dim_ath is offline
Member
 
Join Date: Jan 2008
Posts: 14
dim_ath is on a distinguished road
how can server send messages every 5 min?
hello everyone!

i have implemented a simple lotto system where clients send the number they chose,
and server answers if they win or lose. However i want the server to produce a magic number
every 5 minutes and sends the result to the CLIENTS when the time is over.
Can you help me please? what method need i use?

this is the piece of code:

// control thread's execution
public void run()
{

int message=0;

int rnum=randGen.nextInt(10);
display.append( "\n"+ "THE MAGIC NUMBER IS: " + rnum );

// process connection
try {

// read message from client
do {

try {
message = input.readInt();
if (message==rnum){output.writeUTF("SERVER>>> YOU WON: MAGIC NUMBER IS: " +rnum);}
else {output.writeUTF("SERVER>>> YOU LOSE: MAGIC NUMBER IS: " +rnum);}
display.append( "\n\n" +"PLAYER " + clientNumber + " SELECTED NUMBER " + message );
display.setCaretPosition( display.getText().length() );
}

// process problems reading from client
catch ( IOException ioException ) {
display.append( "\nUnknown object type received" );
}

} while ( message!=-1 );

display.append( "\nClient terminated connection" );
display = null;
}




// close streams and socket
finally {

try {
output.close();


input.close();
connection.close();
}

// process problems with I/O
catch ( IOException ioException ) {
ioException.printStackTrace();
}

clients.remove( this );
}


} // end method run

Last edited by dim_ath : 01-10-2008 at 12:05 PM.
Reply With Quote
Sponsored Links