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 {
|
public static void readPingSendPong(ServerSocket server) throws Exception {
|
||||||
boolean active = true;
|
boolean active = true;
|
||||||
while (active) {
|
|
||||||
// accepter une connexion
|
|
||||||
SSLSocket sslsocket = (SSLSocket) server.accept();
|
SSLSocket sslsocket = (SSLSocket) server.accept();
|
||||||
InputStream in = sslsocket.getInputStream();
|
InputStream in = sslsocket.getInputStream();
|
||||||
OutputStream out = sslsocket.getOutputStream();
|
OutputStream out = sslsocket.getOutputStream();
|
||||||
|
while (active) {
|
||||||
|
// accepter une connexion
|
||||||
|
|
||||||
// lire PING
|
// lire PING
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||||
String message = reader.readLine();
|
String message = reader.readLine();
|
||||||
int id = -1;
|
int id = -1;
|
||||||
if(message.startsWith("ping")){
|
if(message.equals("tg")){
|
||||||
|
active = false;
|
||||||
|
}
|
||||||
|
else if(message.startsWith("ping")){
|
||||||
String num = message.replaceFirst("^" + "ping", "");
|
String num = message.replaceFirst("^" + "ping", "");
|
||||||
try {
|
try {
|
||||||
id = Integer.parseInt(num);
|
id = Integer.parseInt(num);
|
||||||
|
// écrire PONG vers le client
|
||||||
|
out.write(("pong"+id+"\n").getBytes());
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// écrire PONG vers le client
|
|
||||||
out.write(("pong"+id).getBytes());
|
|
||||||
in.close();out.close();sslsocket.close();
|
|
||||||
}
|
}
|
||||||
|
in.close();out.close();sslsocket.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user