segunda-feira, 22 de novembro de 2010

Atualizando

A classe danadinha do servidor não estava me mandando o valor
então refiz;
------------------------
ServidorSocketDM2.java
================================================================================================


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

/**
*
* @author danilo
*/
public class ServidorSocketDM2 {
private int nummaxit=4;
private int porta1=1025;
private String clientSentence1;
private String capitalizedSentence1;
private CharSequence strsair="+1d2+";
private boolean sair=false;
private ServerSocket welcomeSocket1 ;
private Socket connectionSocket1;
private BufferedReader inFromClient1;
private DataOutputStream outToClient1;

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void main(String argv[]) throws Exception
{
this.main1_2(argv);
//this.main1_1(argv);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void main1_1(String argv[]) throws Exception
{
String clientSentence;
String capitalizedSentence;
int i;

ServerSocket welcomeSocket = new ServerSocket (this.porta1);

while(true) {
Socket connectionSocket = welcomeSocket.
accept();
for(i=0; (i {
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader
(connectionSocket.getInputStream()));
DataOutputStream outToClient =
new DataOutputStream
(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
capitalizedSentence =
clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void main1_2(String argv[]) throws Exception
{
// String clientSentence;
// String capitalizedSentence;
int i;

//ServerSocket welcomeSocket = new ServerSocket (this.porta1);
this.abrirConexao1_2();
while(true) {
//Socket connectionSocket = welcomeSocket.accept();
this.processarAntesDoFor1_2();

for(i=0; (i {

/*
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader
(connectionSocket.getInputStream()));
DataOutputStream outToClient =
new DataOutputStream
(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
*/
this.processaANTESDeLerapartirdoCliente();
//capitalizedSentence = clientSentence.toUpperCase() + '\n';
this.processaStringdoCliente_clientSentence1();
/*
* esse é o método principal;
* this.processaStringdoCliente_clientSentence1();
*/
//outToClient.writeBytes(capitalizedSentence);
this.enviarParaCliente();
}
this.fECHARConexao1_2();
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void abrirConexao1_2() throws UnknownHostException, IOException
{
this.welcomeSocket1 = new ServerSocket(this.porta1);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void fECHARConexao1_2() throws UnknownHostException, IOException
{
this.pRocessarDepoisDeFecharOFOR1_2();
this.connectionSocket1.close();

}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void atualiar_valor_do_sair()
{
String a1=this.strsair.toString();
if(this.clientSentence1.toUpperCase().contains(a1.toUpperCase())==true)
{
this.sair=true;
}
String vsf;
vsf="\n----------------\n";
vsf=vsf+" atualiar_valor_do_sair() ";
vsf=vsf+" \n_________________\n ";
vsf=vsf+" a1.toUpperCase() "+a1.toUpperCase();
vsf=vsf+"\n this.sentence1.toUpperCase() "+this.clientSentence1.toUpperCase();
vsf=vsf+"\n this.sair "+ this.sair;
vsf=vsf+"\n---------------- \n----------------\n ";
//System.out.println(vsf);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void atualiar_valor_do_sair2()
{
if(this.sair=false==true)
this.sair=false;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void pRocessarDepoisDeFecharOFOR1_2() throws UnknownHostException, IOException
{
String cac;
this.atualiar_valor_do_sair2();
cac ="\n Valores das variaveis:\n";
cac =cac+"\n this.sair:\n"+this.sair;
cac =cac+"\n this.strsair:\n"+this.strsair;
cac =cac+"\n this.nummaxit:\n"+this.nummaxit;
cac =cac+"\n this.capitalizedSentence1:\n"+this.capitalizedSentence1;
cac =cac+"\n this.clientSentence1:\n"+this.clientSentence1;
cac =cac+"\n this.connectionSocket1.toString():\n"+this.connectionSocket1.toString();
cac =cac+"\n this.welcomeSocket1.toString():\n"+this.welcomeSocket1.toString();


System.out.println(cac);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public void enviarParaCliente() throws UnknownHostException, IOException
{
this.atualiar_valor_do_sair();
//outToClient.writeBytes(capitalizedSentence);
this.outToClient1.writeBytes(this.capitalizedSentence1);
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void processarAntesDoFor1_2() throws UnknownHostException, IOException
{
//Socket connectionSocket = welcomeSocket.accept();
this.connectionSocket1 = this.welcomeSocket1.accept();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void processaANTESDeLerapartirdoCliente() throws IOException {
/*
instancia os objetos para poder
* colocar em this.clientSentence1
* o valor que o cliente mandou
*/
this.inFromClient1 =new BufferedReader(new InputStreamReader(this.connectionSocket1.getInputStream()));
//BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
this.outToClient1 = new DataOutputStream (this.connectionSocket1.getOutputStream());
// DataOutputStream outToClient = new DataOutputStream (connectionSocket.getOutputStream());
// clientSentence = inFromClient.readLine();
this.clientSentence1 =this.inFromClient1.readLine();

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void processaStringdoCliente_clientSentence1() throws IOException {
/*
i
*/
this.capitalizedSentence1 = "\""+this.clientSentence1.toUpperCase()+"\" \n";
//capitalizedSentence = clientSentence.toUpperCase() + '\n';
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

}


================================================================================================





------------------------
ClienteSocketDM2.java
================================================================================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

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

/**
*
* @author danilo
*/
public class ClienteSocketDM2 {
private int nummaxit=4;
private int porta1=1025;
private String sentence1;
private String modifiedSentence1;
private String host1="localhost";
private CharSequence strsair="+1d2+";
private boolean sair=false;
private Socket clientSocket1;
private DataOutputStream outToServer1;
private BufferedReader inFromServer1;
private BufferedReader inFromUser1;




//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



public void main(String argv[]) throws Exception
{
this.main1_2(argv);
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void main1_1(String argv[]) throws Exception
{
int i;
String sentence;
String modifiedSentence;
BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
Socket clientSocket = new Socket("localhost", 6789);



for(i=0; (i {
System.out.println("|> ");
DataOutputStream outToServer = new DataOutputStream( clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader (new InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);

}
clientSocket.close();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void main1_2(String argv[]) throws Exception
{
int i;
this.set_inFromUser1_2();
this.abrirConexao1_2();

for(i=0; (i {
this.processaANTESDeEnviarParaServidor();
this.enviarParaServidor();
this.processaDEPOISDeEnviarParaServidor();
}

this.fECHARConexao1_2();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void set_inFromUser1_2()
{
this.inFromUser1 = new BufferedReader( new InputStreamReader(System.in));
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void abrirConexao1_2() throws UnknownHostException, IOException
{
this.clientSocket1 = new Socket(this.host1,this.porta1);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void fECHARConexao1_2() throws UnknownHostException, IOException
{
this.pRocessarDepoisDeFecharOFOR1_2();
this.clientSocket1.close();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void atualiar_valor_do_sair()
{
String a1=this.strsair.toString();
if(this.sentence1.toUpperCase().contains(a1.toUpperCase())==true)
{
this.sair=true;
}
String vsf;
vsf="\n----------------\n";
vsf=vsf+" atualiar_valor_do_sair() ";
vsf=vsf+" \n_________________\n ";
vsf=vsf+" a1.toUpperCase() "+a1.toUpperCase();
vsf=vsf+"\n this.sentence1.toUpperCase() "+this.sentence1.toUpperCase();
vsf=vsf+"\n this.sair "+ this.sair;
vsf=vsf+"\n---------------- \n----------------\n ";
//System.out.println(vsf);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void atualiar_valor_do_sair2()
{
if(this.sair=false==true)
this.sair=false;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void pRocessarDepoisDeFecharOFOR1_2() throws UnknownHostException, IOException
{
String cac;
this.atualiar_valor_do_sair2();
cac ="\n Valores das variaveis:\n";
cac =cac+"\n this.sair:\n"+this.sair;
cac =cac+"\n this.strsair:\n"+this.strsair;
cac =cac+"\n this.nummaxit:\n"+this.nummaxit;
cac =cac+"\n this.sentence1:\n"+this.sentence1;
cac =cac+"\n this.modifiedSentence1:\n"+this.modifiedSentence1;
cac =cac+"\n this.clientSocket1.toString():\n"+this.clientSocket1.toString();

System.out.println(cac);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public void enviarParaServidor() throws UnknownHostException, IOException
{
/*
lê a informação apartir do teclado
* e prepara objetos para enviar
*/
//outToServer.writeBytes(sentence + '\n');
this.atualiar_valor_do_sair();
this.sentence1=this.sentence1+'\n';
this.outToServer1.writeBytes(this.sentence1);
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void processaDEPOISDeEnviarParaServidor() throws UnknownHostException, IOException
{/*
faz alguma coisa com a resposta do servidor
*/
///modifiedSentence = inFromServer.readLine();
String cacete;
this.modifiedSentence1=this.inFromServer1.readLine();
// System.out.println("FROM SERVER: " + modifiedSentence);
cacete="DO SErVIDOR: " + this.modifiedSentence1;
System.out.println(cacete);

}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public void processaANTESDeEnviarParaServidor() throws UnknownHostException, IOException
{/*
lê a informação apartir do teclado
* e prepara objetos para enviar
*/
System.out.println("|> ");
this.outToServer1 = new DataOutputStream( this.clientSocket1.getOutputStream());
//DataOutputStream outToServer = new DataOutputStream( clientSocket.getOutputStream());
// BufferedReader inFromServer = new BufferedReader (new InputStreamReader(clientSocket.getInputStream()));
this.inFromServer1 = new BufferedReader (new InputStreamReader( this.clientSocket1.getInputStream()));
/* abaixo efetivamente coloca na string sentence1 o que foi digitado*/
this.sentence1 = this.inFromUser1.readLine();
//sentence = inFromUser.readLine();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------






}

================================================================================================



------------------------
a1Cliente.java
================================================================================================
package rect;

/**
*
* @author danilo
*/
public class a1Cliente {
public static void main(String argv[]) throws Exception
{
ClienteSocketDM2 cdm2 = new ClienteSocketDM2 ();
cdm2.main(argv);
}
}
================================================================================================



------------------------
z1Serv.java
================================================================================================

package rect;

/**
*
* @author danilo
*/
public class z1Serv {
public static void main(String argv[]) throws Exception
{
ServidorSocketDM2 sdm2 = new ServidorSocketDM2 ();
sdm2.main(argv);
}

}

================================================================================================



para compilar sem ser nos projetos do netbeans comece tirando, os packages e se vire, é apenas um backup-meu



Nenhum comentário: