erlang android 通讯

来源:互联网 发布:网络上赌博怎么处罚 编辑:程序博客网 时间:2024/06/07 18:18

设计到粘包的问题,直接上代码

erlang 设置 {packet,4}

android端

public byte[] packetData(byte[] sendData){byte[] headerBytes = intToByte(sendData.length);byte[] sendBytes = new byte[headerBytes.length + sendData.length];System.arraycopy(headerBytes, 0, sendBytes, 0, headerBytes.length);System.arraycopy(sendData, 0, sendBytes, headerBytes.length, sendData.length);return sendBytes;}    public byte[] intToByte(int i) {        byte[] abyte0 = new byte[4];        abyte0[3] = (byte) (0xff & i);        abyte0[2] = (byte) ((0xff00 & i) >> 8);        abyte0[1] = (byte) ((0xff0000 & i) >> 16);        abyte0[0] = (byte) ((0xff000000 & i) >> 24);        return abyte0;    }

原创粉丝点击