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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*
$RCSfile$
$Author$
Last Update: $Date$
$Revision$
REVISION HISTORY:
$Log$
Revision 1.1 1997/01/31 01:11:08 sumedh
Added the Nexus II source code files.
# Revision 1.2 1996/12/07 06:27:38 rajeev
# yaah paranoid backup ...
#
# Revision 1.1 1996/12/06 18:23:45 rajeev
# Initial revision
#
# Revision 1.1 1996/12/02 06:07:53 rajeev
# Initial revision
#
# Revision 1.1 1996/12/02 06:02:24 rajeev
# Initial revision
#
*/
// This class encapsulates a dataPacket
// Will encapsulate the byteStream as a characterStream into a single thing
// no packets for now
// package NexusII.networking ;
//import NexusII.client.* ;
public class dataPacket implements consts, Cloneable{
private String clientName ;
private String roomName ;
private String contentType ;
private String contentLength ;
private String content ;
// constructor -- will create the data packet
public dataPacket(byte[] header, byte[] body) {
int len = FIELD_LENGTH ;
clientName = new String(header,0,0,len);
roomName = new String(header,0,1*len,len);
contentType = new String(header,0,2*len,len);
contentLength = new String(header,0,3*len,len);
content = new String(body,0);
if(DEBUG)
System.out.println("datapacket: Constructed packet with header " + header + " and body " + body);
}
// another constructor for length 0 packets
public dataPacket(String client, String room, String type,String len)
{
clientName = new String(client);
roomName = new String(room);
contentType = new String(type);
contentLength = new String(len);
content = new String();
}
// another one for some data also
public dataPacket(String client, String room, String type,String len,String data)
{
this(client,room,type,len);
content = new String(data);
}
// return the data in bytized header and body
public void bytize(byte[] header, byte[] body)
{
// clear the header and body -- fill them with whitespace
String white_space = new String(" ");
if(DEBUG) {
System.out.println("dataPacket: length is " + new Integer(contentLength.trim()).intValue() + "\n");
}
int len = FIELD_LENGTH ;
// copy the header
clientName.getBytes(0,clientName.length(),header,0);
roomName.getBytes(0,roomName.length(),header,len*1);
contentType.getBytes(0,contentType.length(),header,len*2);
contentLength.getBytes(0,contentLength.length(),header,len*3);
int body_len = (new Integer(contentLength.trim())).intValue();
// copy the body also
content.getBytes(0,body_len,body,0);
}
public int contentLength() {
return new Integer(contentLength.trim()).intValue();
}
// Returns the destination for the current packet
public String destination(){
return roomName.trim() ;
}
public String contentType() {
return contentType.trim() ;
}
public String content() {
return content.trim() ;
}
public String clientName() {
return clientName.trim() ;
}
}
// of class datapacket
|