Child pages
  • JSPacket

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Div
styledisplay:none

DO NOT EDIT THE CONTENT OF THIS PAGE DIRECTLY (EXCEPT INSIDE THE DIV BELOW WITH ID=DESCRIPTION), UNLESS YOU KNOW WHAT YOU'RE DOING.
THE STRUCTURE OF THE CONTENT IS VITAL IN BEING ABLE TO AUTO UPDATE THE CONTENT THROUGH THE DOC GENERATOR.

Div
iddescription



HTML Table
id
classservoy sSummary
Colgroup Tag
Col
width80px
Col
Table Head (thead)
Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan2
Property Summary
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
index
Returns the current position in the byte array of the packet.



HTML Table
id
classservoy sSummary
Colgroup Tag
Col
width80px
Col
Table Head (thead)
Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan2
Method Summary
Table Row (tr)
Table Cell (td)
byte[]
Table Cell (td)
getByteArray()
Returns the content of the package into a byte array.
Table Row (tr)
Table Cell (td)
String
Table Cell (td)
getHost()
Returns the name of the host that sent the packet.
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
getLength()
Returns the length of the packet in bytes.
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
getPort()
Returns the port where the packet originated from.
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
readByte()
Reads an 8 bits byte value from the packet, starting from the current index.
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
readInt()
Reads a 32 bits int value from the packet, starting from the current index.
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
readShort()
Reads a 32 bits short value from the packet, starting from the current index.
Table Row (tr)
Table Cell (td)
String
Table Cell (td)
readUTF()
Reads a UTF-8 string from the packet, starting from the current index.
Table Row (tr)
Table Cell (td)
String
Table Cell (td)
readUTF(length)
Reads a UTF-8 string from the packet, starting from the current index.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
writeByte(number)
Writes one byte into the packet, at the current index.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
writeBytes(bytes)
Writes an array of bytes into the packet, at the current index.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
writeInt(number)
Writes a 32 bits int into the packet, at the current index.
Table Row (tr)
Table Cell (td)
void
Table Cell (td)
writeShort(number)
Writes a 16 bits short value into the packet, at the current index.
Table Row (tr)
Table Cell (td)
Number
Table Cell (td)
writeUTF(string)
Writes an UTF-8 encoded string into the packet, at the current index.



HTML Table
idproperty
classservoy sDetail
Colgroup Tag
Col
colspan2
width100%
Col
Table Head (thead)
Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan2
Property Details
Table Body (tbody)
idindex
Table Row (tr)
idname
Table Cell (td)

index

Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Returns the current position in the byte array of the packet. The next read/write operation will occur at this position.
This is a 0 based index.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Number
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('an int is: ' + packet.readInt());
		application.output('moved to index: ' + packet.index);
		application.output('a short is: ' + packet.readShort());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 



HTML Table
idfunction
classservoy sDetail
Colgroup Tag
Col
colspan2
width100%
Col
Table Head (thead)
Table Row (tr)
styleheight: 30px;
Table Head (th)
colspan2
Method Details
Table Body (tbody)
idgetByteArray
Table Row (tr)
idname
Table Cell (td)

getByteArray

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
byte[]
Span
stylefont-weight: bold;
getByteArray
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Returns the content of the package into a byte array.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
byte[]
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		var bytes = packet.getByteArray();
		application.output('received a packet of length: ' + bytes.length);
		for (var i=0; i<bytes.length; i++)
			application.output(bytes[i]);
		}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idgetHost
Table Row (tr)
idname
Table Cell (td)

getHost

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
String
Span
stylefont-weight: bold;
getHost
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Returns the name of the host that sent the packet.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
String
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('message is: ' + packet.readUTF());
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idgetLength
Table Row (tr)
idname
Table Cell (td)

getLength

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
Number
Span
stylefont-weight: bold;
getLength
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Returns the length of the packet in bytes.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Number
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('message is: ' + packet.readUTF());
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idgetPort
Table Row (tr)
idname
Table Cell (td)

getPort

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
Number
Span
stylefont-weight: bold;
getPort
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Returns the port where the packet originated from.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Number
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('message is: ' + packet.readUTF());
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idreadByte
Table Row (tr)
idname
Table Cell (td)

readByte

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
Number
Span
stylefont-weight: bold;
readByte
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Reads an 8 bits byte value from the packet, starting from the current index. Advances the index with one position.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Number
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('an int is: ' + packet.readInt());
		application.output('moved to index: ' + packet.index);
		application.output('a short is: ' + packet.readShort());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idreadInt
Table Row (tr)
idname
Table Cell (td)

readInt

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
Number
Span
stylefont-weight: bold;
readInt
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Reads a 32 bits int value from the packet, starting from the current index. Advances the index with 4 positions.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Number
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('an int is: ' + packet.readInt());
		application.output('moved to index: ' + packet.index);
		application.output('a short is: ' + packet.readShort());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idreadShort
Table Row (tr)
idname
Table Cell (td)

readShort

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
Number
Span
stylefont-weight: bold;
readShort
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Reads a 32 bits short value from the packet, starting from the current index. Advances the index with 2 positions.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Number
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('an int is: ' + packet.readInt());
		application.output('moved to index: ' + packet.index);
		application.output('a short is: ' + packet.readShort());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
		application.output('a byte is: ' + packet.readByte());
		application.output('moved to index: ' + packet.index);
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idreadUTF
Table Row (tr)
idname
Table Cell (td)

readUTF

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
String
Span
stylefont-weight: bold;
readUTF
Span
()
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Reads a UTF-8 string from the packet, starting from the current index. If an argument is specified, then it represents the length (in UTF-8 encoded bytes, not characters) of the string to read. If no argument is specified, then first a 32 bits (4 byte) int is read from the packet and that will be the byte length of the string. Advances the index with a number of positions that depends on the length of the read string.
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
String
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('message is: ' + packet.readUTF());
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idreadUTF-Number
Table Row (tr)
idname
Table Cell (td)

readUTF

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
String
Span
stylefont-weight: bold;
readUTF
Span
(length)
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Reads a UTF-8 string from the packet, starting from the current index. If an argument is specified, then it represents the length (in UTF-8 encoded bytes, not characters) of the string to read. If no argument is specified, then first a 32 bits (4 byte) int is read from the packet and that will be the byte length of the string. Advances the index with a number of positions that depends on the length of the read string.
Table Row (tr)
idprs
Table Cell (td)

Parameters

Div
classsIndent
{Number} length
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
String
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
var packet;
while (packet = plugins.udp.getReceivedPacket()) {
	application.output('packet received from ' + packet.getHost() + ':' + packet.getPort());
	if (packet.getLength() > 0) {
		application.output('message is: ' + packet.readUTF());
	}
	else {
		application.output('end of communication.');
		break;
	}
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idwriteByte-Number
Table Row (tr)
idname
Table Cell (td)

writeByte

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
void
Span
stylefont-weight: bold;
writeByte
Span
(number)
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Writes one byte into the packet, at the current index. The index is advanced with one position.
Table Row (tr)
idprs
Table Cell (td)

Parameters

Div
classsIndent
{Number} number
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
void
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
if (!plugins.udp.startSocket('5555', packetReceived)) {
	application.output('Failed to start socket.');
} else {
	var packet = plugins.udp.createNewPacket();
	packet.writeUTF('hello world!');
	plugins.udp.sendPacket('localhost', packet, 1234);
	packet = plugins.udp.createNewPacket();
	packet.writeByte(0xFF);
	packet.writeShort(10001);
	packet.writeInt(2000000001);
	plugins.udp.sendPacket('localhost', packet, 1234);
	var imgBytes = plugins.file.readFile('logo.jpg', 1024);
	packet = plugins.udp.createNewPacket();
	packet.writeBytes(imgBytes);
	plugins.udp.sendPacket('localhost', packet, 1234);
	plugins.udp.stopSocket();
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idwriteBytes-byteArray
Table Row (tr)
idname
Table Cell (td)

writeBytes

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
void
Span
stylefont-weight: bold;
writeBytes
Span
(bytes)
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Writes an array of bytes into the packet, at the current index. The index is advanced with a number of positions equal to the length of the written array.
Table Row (tr)
idprs
Table Cell (td)

Parameters

Div
classsIndent
{byte[]} bytes
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
void
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
if (!plugins.udp.startSocket('5555', packetReceived)) {
	application.output('Failed to start socket.');
} else {
	var packet = plugins.udp.createNewPacket();
	packet.writeUTF('hello world!');
	plugins.udp.sendPacket('localhost', packet, 1234);
	packet = plugins.udp.createNewPacket();
	packet.writeByte(0xFF);
	packet.writeShort(10001);
	packet.writeInt(2000000001);
	plugins.udp.sendPacket('localhost', packet, 1234);
	var imgBytes = plugins.file.readFile('logo.jpg', 1024);
	packet = plugins.udp.createNewPacket();
	packet.writeBytes(imgBytes);
	plugins.udp.sendPacket('localhost', packet, 1234);
	plugins.udp.stopSocket();
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idwriteInt-Number
Table Row (tr)
idname
Table Cell (td)

writeInt

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
void
Span
stylefont-weight: bold;
writeInt
Span
(number)
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Writes a 32 bits int into the packet, at the current index. The index is advances with 4 positions.
Table Row (tr)
idprs
Table Cell (td)

Parameters

Div
classsIndent
{Number} number
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
void
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
if (!plugins.udp.startSocket('5555', packetReceived)) {
	application.output('Failed to start socket.');
} else {
	var packet = plugins.udp.createNewPacket();
	packet.writeUTF('hello world!');
	plugins.udp.sendPacket('localhost', packet, 1234);
	packet = plugins.udp.createNewPacket();
	packet.writeByte(0xFF);
	packet.writeShort(10001);
	packet.writeInt(2000000001);
	plugins.udp.sendPacket('localhost', packet, 1234);
	var imgBytes = plugins.file.readFile('logo.jpg', 1024);
	packet = plugins.udp.createNewPacket();
	packet.writeBytes(imgBytes);
	plugins.udp.sendPacket('localhost', packet, 1234);
	plugins.udp.stopSocket();
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idwriteShort-Number
Table Row (tr)
idname
Table Cell (td)

writeShort

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
void
Span
stylefont-weight: bold;
writeShort
Span
(number)
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Writes a 16 bits short value into the packet, at the current index. The index is advances with 2 positions.
Table Row (tr)
idprs
Table Cell (td)

Parameters

Div
classsIndent
{Number} number
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
void
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
if (!plugins.udp.startSocket('5555', packetReceived)) {
	application.output('Failed to start socket.');
} else {
	var packet = plugins.udp.createNewPacket();
	packet.writeUTF('hello world!');
	plugins.udp.sendPacket('localhost', packet, 1234);
	packet = plugins.udp.createNewPacket();
	packet.writeByte(0xFF);
	packet.writeShort(10001);
	packet.writeInt(2000000001);
	plugins.udp.sendPacket('localhost', packet, 1234);
	var imgBytes = plugins.file.readFile('logo.jpg', 1024);
	packet = plugins.udp.createNewPacket();
	packet.writeBytes(imgBytes);
	plugins.udp.sendPacket('localhost', packet, 1234);
	plugins.udp.stopSocket();
}
Table Row (tr)
classlastDetailRow
Table Cell (td)
 
Table Body (tbody)
idwriteUTF-String
Table Row (tr)
idname
Table Cell (td)

writeUTF

Table Row (tr)
idsig
Table Cell (td)
Span
stylemargin-right: 5px;
Number
Span
stylefont-weight: bold;
writeUTF
Span
(string)
Table Row (tr)
iddes
Table Cell (td)
Div
classsIndent
Writes an UTF-8 encoded string into the packet, at the current index. First the length of the string is written on 4 bytes, then the string is written. The index is advanced with a number of positions equal to the length of the string plus 4.
Table Row (tr)
idprs
Table Cell (td)

Parameters

Div
classsIndent
{String} string
Table Row (tr)
idret
Table Cell (td)

Returns

Div
classsIndent
Number
Table Row (tr)
idsam
Table Cell (td)

Sample

Div
classsIndent
Code Block
languagejavascript
if (!plugins.udp.startSocket('5555', packetReceived)) {
	application.output('Failed to start socket.');
} else {
	var packet = plugins.udp.createNewPacket();
	packet.writeUTF('hello world!');
	plugins.udp.sendPacket('localhost', packet, 1234);
	packet = plugins.udp.createNewPacket();
	packet.writeByte(0xFF);
	packet.writeShort(10001);
	packet.writeInt(2000000001);
	plugins.udp.sendPacket('localhost', packet, 1234);
	var imgBytes = plugins.file.readFile('logo.jpg', 1024);
	packet = plugins.udp.createNewPacket();
	packet.writeBytes(imgBytes);
	plugins.udp.sendPacket('localhost', packet, 1234);
	plugins.udp.stopSocket();
}
Table Row (tr)
classlastDetailRow
Table Cell (td)