Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.Socket;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintStream;
- import java.net.UnknownHostException;
- public class Reseau
- {
- private Socket sock;
- PrintStream out;
- private BufferedReader in;
- public Reseau()
- {
- }
- public int Connecter(String ip, int sport)
- {
- try
- {
- sock = new Socket(ip, sport);
- return FormaterFlux();
- }
- catch (UnknownHostException e)
- {
- return 1;
- }
- catch (IOException e)
- {
- return 2;
- }
- }
- private int FormaterFlux()
- {
- try
- {
- out = new PrintStream(sock.getOutputStream());
- in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
- return 0;
- }
- catch(IOException e)
- {
- return 10;
- }
- }
- public int Recevoir(StringBuffer recu)
- {
- try
- {
- String msg=in.readLine();
- recu.append(msg);
- if (msg!= null)
- return 0;
- else
- return 1;
- }
- catch(IOException e)
- {
- return 2;
- }
- }
- public int Envoyer(String message)
- {
- out.println(message);
- return 0;
- }
- public int Deconnecter()
- {
- try
- {
- sock.close();
- return 0;
- }
- catch (IOException e)
- {
- return 1;
- }
- }
- }
Add Comment
Please, Sign In to add comment