Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. public void demarrer() {
  2.         mySocket = null;
  3.         try {
  4.             mySocket = new DatagramSocket(6789); // port convenu avec les clients
  5.             byte[] buffer = new byte[1000];
  6.             while (true) {
  7.                 DatagramPacket request = new DatagramPacket(buffer,
  8.                         buffer.length);
  9.                 mySocket.receive(request); // réception bloquante
  10.  
  11.                 Requete requete = Requete.unmarshall(request);
  12.                 new Thread(new RequestHandler(requete)).start();
  13.             }
  14.         } catch (SocketException e) {
  15.             System.out.println("Socket: " + e.getMessage());
  16.         } catch (IOException e) {
  17.             System.out.println("IO: " + e.getMessage());
  18.         }
  19.  
  20.         finally {
  21.             if (mySocket != null)
  22.                 mySocket.close();
  23.         }
  24.  
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement