1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
public class Paquet {
public int seqnum = 0;
public int checksum = 0;
public String message = " ";
public Paquet (int seqnum, int checksum, String message) {
this.seqnum = seqnum;
this.checksum = checksum;
this.message = message;
}
public Paquet (byte[] b)
this.seqnum = (int) b[0];
this.checksum = (int) b[1];
byte[] post = new byte[b.length-2];
System.arraycopy(b, 2, post, 0, post.length);
this.message = new String(post);
public byte[] getBytes() {
byte[] num = { (byte)seqnum, (byte)checksum};
byte[] post = post.getBytes();
byte[] pack = new byte[ num.length+post.length];
system.arraycopy(num,0,pack,0,num.length);
System.arraycopy(post,2,pack,num.length,post.length);
return pack;
}
} |
Partager