correction serveur, répond uniquement si il s'agait biend d'un string ping suivi d'un int
This commit is contained in:
@@ -69,27 +69,31 @@ public class Serveur {
|
||||
|
||||
public static void readPingSendPong(ServerSocket server) throws Exception {
|
||||
boolean active = true;
|
||||
while (active) {
|
||||
// accepter une connexion
|
||||
SSLSocket sslsocket = (SSLSocket) server.accept();
|
||||
InputStream in = sslsocket.getInputStream();
|
||||
OutputStream out = sslsocket.getOutputStream();
|
||||
while (active) {
|
||||
// accepter une connexion
|
||||
|
||||
// lire PING
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||
String message = reader.readLine();
|
||||
int id = -1;
|
||||
if(message.startsWith("ping")){
|
||||
if(message.equals("tg")){
|
||||
active = false;
|
||||
}
|
||||
else if(message.startsWith("ping")){
|
||||
String num = message.replaceFirst("^" + "ping", "");
|
||||
try {
|
||||
id = Integer.parseInt(num);
|
||||
// écrire PONG vers le client
|
||||
out.write(("pong"+id+"\n").getBytes());
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
// écrire PONG vers le client
|
||||
out.write(("pong"+id).getBytes());
|
||||
}
|
||||
in.close();out.close();sslsocket.close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user