Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package serveur_mt;
- import java.io.IOException;
- import java.net.ServerSocket;
- import java.net.Socket;
- public class Serveur {
- public final static int DEFAULT_PORT = 6789;
- protected static int port;
- public static void main(String[] args) {
- ServerSocket listen_socket=null;
- if(args.length>0) {
- try {
- port=Integer.parseInt(args[0]);
- }catch(NumberFormatException nfe) {
- usage();
- System.out.println(nfe);
- System.exit(-1);
- }
- }else {
- port=DEFAULT_PORT;
- }
- //création de la socket d'écoute du serveur
- try {
- listen_socket=new ServerSocket(port);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //boucle infinie du serveur
- //on attend des connexions clientes
- while(true) {
- try {
- Socket client=listen_socket.accept();
- Service s=new Service(client);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- private static void usage() {
- System.out.println("Syntaxe: java Serveur [numéro de port]");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement