mirror of
https://github.com/LucasVbr/mini-chat.git
synced 2026-05-16 09:06:54 +00:00
15/11/2022
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package client;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.rmi.UnknownHostException;
|
||||
|
||||
public class Client {
|
||||
public static void main(String[] args) throws IOException {
|
||||
Socket echoSocket = null;
|
||||
PrintWriter out = null;
|
||||
BufferedReader in = null;
|
||||
|
||||
try {
|
||||
echoSocket = new Socket("localhost", 4444);
|
||||
System.out.println("Connecté au serveur");
|
||||
out = new PrintWriter(echoSocket.getOutputStream(), true);
|
||||
in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
|
||||
} catch (UnknownHostException e) {
|
||||
System.out.println("Destination unknown");
|
||||
System.exit(-1);
|
||||
} catch (IOException e) {
|
||||
System.out.println("now to investigate this IO issue");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
|
||||
String userInput;
|
||||
|
||||
while ((userInput = stdIn.readLine()) != null) {
|
||||
out.println(userInput);
|
||||
System.out.println("echo: " + userInput);
|
||||
}
|
||||
|
||||
out.close();
|
||||
in.close();
|
||||
stdIn.close();
|
||||
echoSocket.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user