package rect;
import java.io.*;
import java.net.*;
class TCPClient {
private static BufferedReader inFromUser;
private static String sentence;
private static String modifiedSentence;
private static Socket clientSocket;
private static String host;
private static int porta;
private static DataOutputStream outToServer;
private static InputStreamReader inputStreamReader;
private static BufferedReader inFromServer ;
private static CharSequence strsair="tchau";
private static boolean sair=false;
public static void main(String argv[]) throws Exception
{
host="localhost";
porta=6789;
InputStream iunputSteam=System.in;
InputStreamReader inputStreamReadertcl;
OutputStream outputStreamcliente;
InputStream inputStreamclientSocket;
clientSocket = new Socket(host, porta);
for(int i=0; (i<4)&&(sair==false); i++)
{
inputStreamReadertcl=new InputStreamReader(iunputSteam);
inFromUser =new BufferedReader(inputStreamReadertcl);
outputStreamcliente=clientSocket.getOutputStream();
outToServer = new DataOutputStream( outputStreamcliente);
inputStreamclientSocket=clientSocket.getInputStream();
inputStreamReader=new InputStreamReader (inputStreamclientSocket);
inFromServer = new BufferedReader (inputStreamReader);
/*sentença digitada pelo cliente*/
sentence = inFromUser.readLine();
if(sentence.contains(strsair)==true)
sair=true;
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
modifiedSentence="FROM SERVER: "+modifiedSentence+"\n sair ="+sair+"\n" ;
System.out.println(modifiedSentence);
}
System.out.println("desconectando servidor "+"clientSocket.toString()"+clientSocket.toString());
clientSocket.close();
}
public void testar(String argv[]) throws Exception
{
}
}
sexta-feira, 19 de novembro de 2010
Assinar:
Postar comentários (Atom)
Nenhum comentário:
Postar um comentário