String str=      (char)255 +   (char)255  +"1"   ;
        
              
              byte[] sendbuf =    str.getBytes();
               outputPacket = new DatagramPacket(sendbuf,sendbuf.length,
                  remoteIP,2280);
                                
            
    
                 logSocket.send(outputPacket);
udp 收到的是  0x35 0x31 0x30 0x31  ,  为什么?正确应该是 0xff 0xff 0x31

解决方案 »

  1.   

    String str= (char)255 + (char)255 +"1" ;
    这多费劲,最好写自己和别人都容易看懂理解的。
    0x35 0x31 0x30 0x31从结果上猜:255 + 255 = 510
      

  2.   

    补充问题: 
    String str= (char)255 + (char)255 +"1" ;
       
       
      byte[] sendbuf = str.getBytes();
    outputPacket = new DatagramPacket(sendbuf,sendbuf.length,
      remoteIP,2280);
       
     
     
      logSocket.send(outputPacket);
    udp 收到的是 0x35 0x31 0x30 0x31 , 为什么?我想要收到 0xff 0xff 0x31 要怎样做??
      

  3.   

    你的str先添加了两个char,应该是这样:String str = (char)(255 + 255) + "1"; // 5101你需要实现:String str = (char) 255 + "" + (char) 255 + "1";或者使用String.format:String str = String.format("%c%c%d", 255, 255, 1);