NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package Client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;


public class Client {
private Socket clientSocket;

//Encapsuler system standard input du clent avec BufferedReader
private BufferedReader sin;

//Encapsuler OutputStream du client (envoyé au serveur) avec PrintWriter
private PrintWriter os;

//Encapsuler InputStream du serveur au client avec BufferedReader
private BufferedReader is;

private Command com;

Client(String s) {
try {
clientSocket = new Socket(s, 4700);
if (clientSocket != null){
System.out.print("Se connecter au serveur ");
System.out.println(s);
}
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
com = new Command();
}

public void run() {
try {
sin = new BufferedReader(new InputStreamReader(System.in));
os = new PrintWriter(clientSocket.getOutputStream());
is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String reponse = "";
while(!reponse.equals("Aurevoir")){
String message = selectCom();
System.out.println("Client:" + message);
os.println(message);
os.flush();
reponse = is.readLine();
System.out.println("Server:" + reponse);
//message = selectCom();
}
} catch (Exception e) {
System.out.println(e);
}
}

public void close() {
try {
sin.close();
os.close();
is.close();
clientSocket.close();
}// 关闭Socket
catch (Exception e) {
System.out.println(e);
}

}

public String selectCom() {
String command = "";
System.out.println("Choisir une fonction:[Ajouter|Modifier|Chercher|Lister|Supprimer|Quitter]");
try {
command = sin.readLine();
System.out.println(command);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while (!command.equals("Ajouter") && !command.equals("Modifier")
&& !command.equals("Chercher") && !command.equals("Lister")
&& !command.equals("Supprimer")&& !command.equals("Quitter")) {
System.out.println("Oops!!! Ce n'est pas la bonne fonction!");
return selectCom();
}
// if (!command.equals("bye")) {
// String message = "";
// if (command.equals("Ajouter")) {
//
// message = com.ajouter();
// } else if (command.equals("Modifier")) {
// message = com.modifier();
// } else if (command.equals("Chercher")) {
// message = com.chercher();
// } else if (command.equals("Lister")) {
// message = com.lister();
// } else if (command.equals("Supprimer")) {
// message = com.supprimer();
// } else if (command.equals("Quitter")) {
// message = com.quitter();
// }
// return message;
// }


if (!command.equals("bye")) {
String message = "";
switch (command) {
case "Ajouter":
message = com.ajouter();
break;
case "Modifier":
message = com.modifier();
break;
case "Chercher":
message = com.chercher();
break;
case "Lister":
message = com.lister();
break;
case "Supprimer":
message = com.supprimer();
break;
case "Quitter":
message = com.quitter();
break;
default:
break;
}
return message;
}
else
return "bye";
}

public static void main(String args[]) {
//Connecter au serveur dont l'adresse IP est "..."
//Client client = new Client("127.0.0.1"); //localhost test
Client client = new Client("192.168.1.31");
client.run();
client.close();
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.