sexta-feira, 19 de novembro de 2010

Atualizando o código do servidor abaixo

package rect;
import java.io.*;
import java.net.*;


class TCPServer {

private static String clientSentence;
private static String capitalizedSentence;
private static ServerSocket welcomeSocket;
private static int porta;
private static Socket connectionSocket;
private static BufferedReader inFromClient;
private static InputStreamReader inputStreamReader;
private static InputStream getInputStream1;
private static OutputStream getOutputStream1;
private static DataOutputStream outToClient;
private static CharSequence strsair="tchau";
private static boolean sair=false;

public static void main(String argv[]) throws Exception
{
porta = 6789;
welcomeSocket = new ServerSocket(porta);

while(true) {
connectionSocket = welcomeSocket.accept();
for(int i=0; (i<4)&&(sair==false) ; i++)
{
getInputStream1=connectionSocket.getInputStream();
inputStreamReader= new InputStreamReader(getInputStream1);
inFromClient = new BufferedReader(inputStreamReader);
getOutputStream1 =connectionSocket.getOutputStream();
outToClient = new DataOutputStream(getOutputStream1 );
/* sentença do cliente cliente sentence*/
clientSentence = inFromClient.readLine();

if(clientSentence.contains(strsair)==true)
sair=true;
/*
* */

System.out.println("clientSentence = inFromClient.readLine(); ="+clientSentence+" sair= "+sair);



capitalizedSentence = clientSentence.toUpperCase() + '\n';
/* mandando para o cliente outToClient.writeBytes(capitalizedSentence); */
outToClient.writeBytes(capitalizedSentence);
}
System.out.println("desconectando servidor "+"welcomeSocket.toString()"+welcomeSocket.toString());
sair=false;

}
}
}

Nenhum comentário: