jovemnf
Outubro 31, 2012, 6:25am
#1
Bom dia… estou enviando via socket a string: 535600321600003E3305025090FE9500FEEFF900FD65DA00960055015090FE96000E020100001C2700000001337E009CBC3400
e na outra ponta estou recebendo a seguinte string: 535600221600003E3305025094579500FEEFF455FD65DA00960055015090FE96000E020100001C2700000001337E009CBC3400
alguém saberia me explicar o que pode ser?
Sem o código do programa fica difícil.
jovemnf
Outubro 31, 2012, 6:44am
#3
Para enviar:
private OutputStream fromClientSocket;
private void ACK() throws IOException{
try {
String ack = "5356000D0000002BF400060000";
fromClientSocket.write( this.stringToByte(ack) );
fromClientSocket.flush();
} catch (Exception ex) {
Logger.getLogger(TCPClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
private byte[] stringToByte(String str ){
byte[] stringCompleta = new byte[str.length() / 2];
int j = 0;
for (int i = 0; i < str.length(); i += 2)
{
stringCompleta[j] = (byte) Integer.parseInt(str.substring(i, i + 2), 16);
j++;
}
return stringCompleta;
}
e para receber
public void run(){
BufferedReader in;
try {
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
System.out.println ("Waiting...");
while( clientSocket.isConnected() ){
char[] cbuf = new char[224];
in.read(cbuf);
String texto = getStringFromUnicode( cbuf );
System.out.println( texto );
cbuf = null;
}
System.err.println("Fechando Comunicação com o Rastreador...");
in.close();
clientSocket.close();
} catch (IOException e) {
System.err.println("Conexão Fechada com o Rastredor..");
} catch (Exception ex) {
Logger.getLogger(TCPClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
protected String getStringFromUnicode(char[] codes) throws IOException
{
if (codes == null) {
return null;
}
final StringBuilder hex = new StringBuilder(2 * codes.length);
for (final byte b : codes) {
final int hiVal = (b & 0xF0) >> 4;
final int loVal = b & 0x0F;
hex.append((char) ('0' + (hiVal + (hiVal / 10 * 7))));
hex.append((char) ('0' + (loVal + (loVal / 10 * 7))));
}
return hex.toString();
}