协议采用定长包头,长度为7,
心跳包请求包0x00000002,
心跳包发送包0x80000002,什么是数据包,怎样创建这种格式的数据包,怎样自己设计,求大神讲解下!socket通讯java心跳数据包

解决方案 »

  1.   

      byte[] packHead={(byte) 0x1F, (byte) 0x1F};
         byte[] ResponseString = new byte[str1.length()+2+1+4];
         System.arraycopy(packHead, 0, ResponseString, 0, packHead.length);
         byte[] packType ={0x3};
         System.arraycopy(packType, 0, ResponseString, packHead.length, packType.length);
         int len = str1.length();
         byte[] packLen = ConvertUtil.Int2bytes(len);
         System.arraycopy(packLen, 0, ResponseString, packHead.length+packType.length, packLen.length);
         byte[] packXml = ConvertUtil.String2bytes(str1);
         System.arraycopy(packXml, 0, ResponseString, packHead.length+packType.length+packLen.length, packXml.length);