-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.txt
80 lines (64 loc) · 3.57 KB
/
temp.txt
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//processing for no reason... this part could be implemented in GUDPPacket, but no... we shouldn't touch it, because reasons.. //processing for no reason... this part could be implemented in GUDPPacket, but no... we shouldn't touch it, because reasons.. //processing for no reason... this part could be implemented in GUDPPacket, but no... we shouldn't touch it, because reasons...
//buffer input...
byte[] data = s_packet.getData();
s_buffer = ByteBuffer.allocate(s_packet.getLength() + 8); //allocate memory == packet length + header size
s_buffer.order(ByteOrder.BIG_ENDIAN);
s_buffer = ByteBuffer.wrap(data, 0, s_packet.getLength()); //put the received packet's data into this f*king s_buffer...
//buffer input...
int buffer_length = s_buf the header
//s_gudppacket.setVersion(s_buffer.getShort(0));
//s_gudppacket.setType(s_buffer.getShort(2));
//s_gudp the header
//s_gudppacket.setVersion(s_buffer.getShort(0));
//s_gudppacket.setType(s_buffer.getShort(2));
//s_gudp the header
//s_gudppacket.setVersion(s_buffer.getShort(0));
//s_gudppacket.setType(s_buffer.getShort(2));
//s_gudppacket.setSeqno(s_buffer.getInt(4));
//given code
//s_gudppacket = GUDPPacket.encapsulate(s_packet); //this is only done for DATA
//given code
//
//end of the processing for no reason...
----------------------------------------------------------------------
Receive function socket
----------------------------------------------------------------------
//added code needed in decapsulation
//buffer input...
byte[] data = r_packet.getData();
r_buffer = ByteBuffer.allocate(r_packet.getLength() + 8); //allocate memory == packet length + header size
r_buffer = ByteBuffer.wrap(data, 0, r_packet.getLength()); //put the received packet's data into this f*king r_buffer...
r_buffer.order(ByteOrder.BIG_ENDIAN);
//buffer input...
int buffer_length = r_buffer.position(); //we first write to the buffer then get its length with the .position() method
r_gudppacket.setPayloadLength(buffer_length); //set the payload length
r_buffer.position(0); //now we go back to position 0, to start reading the header
r_gudppacket.setVersion(r_buffer.getShort(0));
r_gudppacket.setType(r_buffer.getShort(2));
r_gudppacket.setSeqno(r_buffer.getInt(4));
//
//end of the processing for no reason...
-------------------------------------------------------------------------
Old BSN packet mechanism in send_buffer
-------------------------------------------------------------------------
//BSN
private ByteBuffer BSN_buffer; //header only, BSN needs no payload
private DatagramPacket BSN_packet;
//
//DatagramPacket constructor -->
//DatagramPacket(byte[] buf, int length, SocketAddress address)
//Constructs a datagram packet for sending packets of length length to the specified port number on the specified host.
//send a BSN packet as the 1st packet upon starting
//constructing the BSN header
BSN_buffer.putShort(0, (short)1); //VERSION position 0, version 1
BSN_buffer.putShort(2, (short)2); //TYPE position 2, type 2 (==BSN)
BSN_buffer.putInt(4, sequence_number); //SEQUENCE_NUMBER position 4, randomly generated sequence_number from the constructor
BSN_buffer.order(ByteOrder.BIG_ENDIAN);
//
byte[] BSN_byte_array = new byte[BSN_buffer.remaining()];
BSN_packet = new DatagramPacket(BSN_byte_array, 8, socket.getRemoteSocketAddress());
try{
socket.send(BSN_packet);
}
catch(Exception e){
}