Bukisoh

Reseau.java

Nov 25th, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import java.net.Socket;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.io.PrintStream;
  6. import java.net.UnknownHostException;
  7.  
  8.  
  9. public class Reseau
  10. {
  11.     private Socket sock;
  12.     PrintStream out;
  13.     private BufferedReader in;
  14.    
  15.     public Reseau()
  16.     {
  17.    
  18.        
  19.     }
  20.    
  21.     public int Connecter(String ip, int sport)
  22.     {
  23.         try
  24.         {
  25.         sock = new Socket(ip, sport);
  26.         return FormaterFlux();
  27.         }
  28.        
  29.         catch (UnknownHostException e)
  30.         {
  31.             return 1;
  32.         }
  33.        
  34.         catch (IOException e)
  35.         {
  36.             return 2;
  37.         }
  38.        
  39.     }
  40.    
  41.     private int FormaterFlux()
  42.     {
  43.        
  44.         try
  45.         {
  46.          out = new PrintStream(sock.getOutputStream());
  47.          in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
  48.          return 0;
  49.          }
  50.        
  51.         catch(IOException e)
  52.         {
  53.             return 10;
  54.         }
  55.     }
  56.    
  57.     public int Recevoir(StringBuffer recu)
  58.     {
  59.         try
  60.         {
  61.         String msg=in.readLine();
  62.         recu.append(msg);
  63.         if (msg!= null)
  64.             return 0;
  65.         else
  66.             return 1;
  67.         }
  68.         catch(IOException e)
  69.         {
  70.             return 2;
  71.         }
  72.        
  73.     }
  74.    
  75.            
  76.     public int Envoyer(String message)
  77.     {
  78.         out.println(message);
  79.         return 0;
  80.     }
  81.    
  82.  
  83.    
  84.     public int Deconnecter()
  85.     {
  86.         try
  87.         {
  88.         sock.close();
  89.         return 0;
  90.    
  91.         }
  92.    
  93.         catch (IOException e)
  94.         {
  95.         return 1;
  96.         }
  97.     }
  98. }
  99.  
  100.  
  101.    
  102.  
  103.  
Add Comment
Please, Sign In to add comment