NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/**
*
*/
package serveur;

/**
* @author user
*
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import DATA.ListNickname;
import Requete_Reponse.Reponse;
import Requete_Reponse.Requete;

public class Serveur {
private int port;
private ListNickname list; // List DateBase des surnoms
private Socket clientSocket;

private ObjectOutputStream fluxOut;
private ObjectInputStream fluxIn;

public Serveur(int port) {
this.port = port;
list = new ListNickname(); // A REMPLIR
try {
run();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
* Méthode permettant de lancer le serveur
*
* @throws IOException
* Exception levée si des problémes de flux sont rencontréSs
*/
public void run() throws IOException {

ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(port);
} catch (IOException e) {
System.err.println("Problème sur le port .");

}

System.out.println("Serveur en marche, en attente de connexions...");
clientSocket = null;
try {
clientSocket = serverSocket.accept();
System.out.println("Vous etes bien sur port n°"
+ clientSocket.getPort());
} catch (IOException e) {
System.err.println("Connexion échouée.");

}
analyseRequete();

}

/**
* Methode utilisee pour recevoir un objet envoyé par le client et traiter
* puis envoyer la réponse
*
* @return
*/
void analyseRequete () {


// Creer le buffer de entree
//
if(fluxIn == null) {
// Creer le flux d entree
//
InputStream streamIn= null;
try {
streamIn= clientSocket.getInputStream();
fluxIn= new ObjectInputStream(streamIn);
}
catch (Exception e) {
e.printStackTrace();
System.err.println("Erreur de lecture sur la socket");
System.exit(0);
}
}

System.out.println("en attente de commande du client");
Object req;
try {
while ((req = fluxIn.readObject()) != null) {
if(req!= null) {
//System.out.println("==>" +req);

// Execute la requete et recuperer la reponse
Reponse reponse = ((Requete) req).executer(this.list);
System.out.println("Requete execute ? "+reponse.getIsDone());

//Envoi la reponse au client
// Envoyer la reponse aux clients

// Tester si le flux de sortie a ete initialise
//
if (fluxOut == null) {

// Creer le flux de sortie
//
OutputStream streamOut = null;
try {
streamOut = clientSocket.getOutputStream();
} catch (Exception e) {
System.err.println("Impossible d'ouvir un flux sur la socket serveur");
}

// Creer le buffer de sortie
try {
fluxOut = new ObjectOutputStream(streamOut);
} catch (Exception e) {
System.err.println("Erreur d'ecriture sur la socket serveur");
}
}

// Envoyer le message
try {
fluxOut.writeObject(reponse);

// Forcer l'envoi
//
fluxOut.flush();
} catch (IOException e) {
System.err.println("Impossible d'envoyer de message serveur");
}
}
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
     
 
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.