1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| import java.io.*;
import java.net.*;
public class Client
{
private int PORT=21;
private char [] buf=new char[10000];
private static BufferedReader sin;
private static BufferedReader console;
private static PrintStream sout;
private Socket s=null;
public Client(String []arg)
{
if (arg.length!=1) erreur();
try {
s=new Socket(arg[0],PORT);
sin=new BufferedReader(new InputStreamReader(s.getInputStream()));
console=new BufferedReader(new InputStreamReader(System.in));
sout=new PrintStream(s.getOutputStream());
System.out.println("Connexion : "+ s.getInetAddress()+
" port : "+s.getPort());
String ligne;
while (true)
{
lire();
System.out.print("?");
System.out.flush();
ligne=console.readLine();
sout.println(ligne);
}
}
catch (IOException e) {System.err.println(e);}
finally
{try {if (s!=null) s.close();}
catch (IOException e2){}}
}
public void erreur() {
System.err.println("Usage: java Client <hostname>");
System.exit(1);
}
public void lire()
{
for(int i=0;i<buf.length;i++) buf[i]='\0';
try {
sin.read(buf);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int k=0;
do
{
System.out.print(buf[k]);
k++;
}
while(buf[k]!='\0');
}
} |