sexta-feira, 19 de novembro de 2010

atualizando cliente novamente

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;
private static InputStream iunputSteam=System.in;
private static InputStreamReader inputStreamReadertcl;
private static OutputStream outputStreamcliente;
private static InputStream inputStreamclientSocket;

public static void main(String argv[]) throws Exception
{
host="localhost";
porta=6789;


clientSocket = new Socket(host, porta);
for(int i=0; (i<4)&&(sair==false); i++)
{

inFromUser=getBufferedReaderapartirdeInputStream(iunputSteam);
outToServer = getDataOutputStreamapartirdeSocket(clientSocket );
inFromServer = getBufferedReaderapartirdeInputStreamdosocket(clientSocket);

/*sentença digitada pelo cliente*/
sentence = getStringapartirdeBufferedReader(inFromUser);
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 static BufferedReader getBufferedReaderapartirdeInputStream(InputStream iunputSteam)
{
// throw new UnsupportedOperationException("Not yet implemented");

BufferedReader inFromUser1;

inputStreamReadertcl=new InputStreamReader(iunputSteam);
inFromUser1 =new BufferedReader(inputStreamReadertcl);
return inFromUser1;


}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public static BufferedReader getBufferedReaderapartirdeInputStreamdosocket(Socket socket) throws IOException
{
// throw new UnsupportedOperationException("Not yet implemented");
InputStream iunputSteam1;
iunputSteam1=socket.getInputStream();
return getBufferedReaderapartirdeInputStream(iunputSteam1);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void testar(String argv[]) throws Exception
{

}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public static DataOutputStream getDataOutputStreamapartirdeSocket(Socket socket) throws IOException
{
OutputStream outputStream1;
DataOutputStream dataOutputStream1;
outputStream1=socket.getOutputStream();
dataOutputStream1 = new DataOutputStream( outputStream1);
return dataOutputStream1 ;

}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public static String getStringapartirdeBufferedReader(BufferedReader bufferedReader) throws IOException
{
String s1;
s1 = bufferedReader.readLine();
return s1;
}
//--
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public static String getDataOutputStreamapartirdeBufferedReader(BufferedReader bufferedReader) throws IOException
{
String s1;
s1 = bufferedReader.readLine();
return s1;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



}

Nenhum comentário: