Ola pessoal, estou fazerndo um programa aki q ele converte um int em um byte porem para numeros pqnos como 97 ou 100 ele converte porem numeros maiores (65288) nao, no caso ele converte tudo errado e com alguns sinais de -, preciso converter para poder enviar via socket para um programa em c++
veja meu codigo:
public void sendMsg(Mensagem msg1) throws UnsupportedEncodingException{
ByteBuffer bufferInt=ByteBuffer.allocate(12);
ByteOrder ordem = ByteOrder.LITTLE_ENDIAN;
bufferInt.order(ordem);
bufferInt.putInt(msg1.getTamanho());
//bufferInt.putLong(msg1.getId());
//bufferInt.put(intToFourBytes(65288, false));
bufferInt.putInt(65288);
byte[] msgTotal=new byte[12];
msgTotal=bufferInt.array();
try {
System.out.println("Mensagem: "+msgTotal[0]+msgTotal[1]+msgTotal[2]+msgTotal[3]+" "+msgTotal[4]+msgTotal[5]+msgTotal[6]+msgTotal[7]);
envio(msgTotal);
} catch (SocketException ex) {
Logger.getLogger(ConexaoLinux.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnknownHostException ex) {
Logger.getLogger(ConexaoLinux.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ConexaoLinux.class.getName()).log(Level.SEVERE, null, ex);
}
}
e a funcao q envia eh esta:
private void envio(byte[] bytes) throws SocketException, UnknownHostException, IOException{
DatagramSocket s = new DatagramSocket(); //udp
InetAddress adr=InetAddress.getByName("192.168.56.2"); //udp
DatagramPacket question = new DatagramPacket(bytes, bytes.length,adr,30000); //udp
s.send(question); //udp
}
qm souber algo ajudaria muito
vlw