Bom tenho o seguinte código abaixo para comnuicar com o ACBr Monitor, porém não consigo passar comandos pelo “writeToReadFromSocket(“bla, bla, blá”)”, alguém que já tenha utilizado o “ACBr”, poderia me ajudar ??? vlw agradeço a todos… =)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package acbrmonitor;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStreport java.io.DataOutputStrea.io.DataInputStream;
import java.io.DataOutputStreeption;
import java.io.InputStreamReader;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Fred
*/
public class ACBrMonitorClient {
private Socket acbr;
private PrintWriter enviaComando = null;
private BufferedReader recebeComando = null;
private String finalResposta = "\u0003";
public ACBrMonitorClient(String host, int port) {
try {
InetAddress hostName = InetAddress.getByName(host);
acbr = new Socket(hostName, port);
enviaComando = new PrintWriter(acbr.getOutputStream());
recebeComando = new BufferedReader(new InputStreamReader(acbr.getInputStream()));
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
Logger.getLogger(ACBrMonitorClient.class.getName()).log(Level.SEVERE, null, ex);
}
//loop para limpar o cabeçalho da conexao com o acbr
short byteLido = -1;
String leitura = "";
while (byteLido != 3) {
byteLido = (short) recebeComando.read();
if (byteLido != 3) {
leitura += (char) byteLido;
}
}
System.out.println("Leitura: " + leitura);
} catch (UnknownHostException ex) {
System.out.println("Host Desconhecido: " + ex.getMessage());
} catch (IOException ex) {
System.out.println("Erro: " + ex.getMessage());
}
}
public String writeToReadFromSocket(String writeTo) throws Exception {
String comando = toUpper(writeTo);
enviaComando.println(comando);
enviaComando.flush();
if ("BYE".equals(comando)) {
enviaComando.close();
recebeComando.close();
acbr.close();
return "FIM";
}
//faz a leitura do retorno do acbr
short b = -1;
String retorno = "";
while (b != 3) {
b = (short) recebeComando.read();
if (b != 3) {
retorno += (char) b;
}
}
return retorno;
}
private String toUpper(String upper) {
StringBuffer retorno = new StringBuffer();
for (char i : upper.toCharArray()) {
retorno.append(Character.toUpperCase(i));
}
return retorno.toString();
}
}
NFe.StatusServico