Ciao ragazzi,
ho un thread in java che,ogni tanto manda un comando al server (tramite socket)!
io vorrei che pero questa socket,nel caso il server non esiste non fermi il programma...come devo gestire le eccezzioni??c'è qlc modo o devo verificare prima se esiste il server???
Il client è cosi:
public void start(){
//Connessione della Socket con il Server
Socket socket = null;
try {
socket = new Socket("127.0.0.t", 7777);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Stream di byte da passare al Socket
DataOutputStream os = null;
try {
os = new DataOutputStream(socket.getOutputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput = "PROVA";
try {
os.writeBytes(userInput + '\n');
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Chiusura dello Stream e del Socket
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Eccoo..io ogni tanto richiamo questa funzione,voglio che , se il server non esiste, cmq nn blocca il mio programma!!!
avete qualche idea??
grazie mille